u2 - #Code is broken into 2 parts, Part 1 and Part 2 #Part 1

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 #Code is broken into 2 parts, Part 1 and Part 2 #Part 1 rm(list=ls(all=TRUE)) ls() n<- c(25,30,36,43,52,62,75,90,107,129,155,186,223,267,321,385,462,555,666,799,958,1150,1380,1656,1987,2385) l <- length(n) k = 1000 r = 500 #compute avg relative error are <- function(b,v) { l <- length(b) c <- 1/(l*v) sum <- 0 for(i in 1:l) { sum = sum + abs( v-b[i] ) } return(c*sum) } #bootstrap function for first question #returns variance of median bootstrapping and medians boo <- function(data,r) { median <- matrix(nrow=r,ncol=1) m <- length(data) for(i in 1:r) { s<-sample(1:m,size=m,replace=T) median[i,1] <- median(data[s]) } return( list(v=var(median),m=median) ) } #first question genkmed <- function(n) { median.u <- matrix(nrow=k,ncol=1) median.chi <- matrix(nrow=k,ncol=1) var.b.u <- matrix(nrow=1000,ncol=1) var.b.chi <- matrix(nrow=1000,ncol=1) for(i in 1:k) { data.u<- runif(n) median.u[i,1] <- median(data.u) data.chi<-rchisq(n,df=3)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sheet1 Page 2 median.chi[i,1] <- median(data.chi) #bootstrap var.b.u[i,1] <- boo(data.u,r)$v var.b.chi[i,1] <- boo(data.chi,r)$v } var.u <- var(median.u)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/19/2009 for the course MATH compstat taught by Professor Qian during the Spring '09 term at FAU.

Page1 / 10

u2 - #Code is broken into 2 parts, Part 1 and Part 2 #Part 1

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online