I didn't see bootstrap steps in your code. One way to modify your codes for (Ncount in 1:100) { b.data<-data[sample(1:nrow(data),replace=T),] y <-b.data[,1] x <-b.data[,2] n <- length(x) ... ### make appropriate changes if needed }
Weidong Gu On Wed, Jul 20, 2011 at 6:09 PM, Val <valkr...@gmail.com> wrote: > Hi all, > > I am facing difficulty on how to use bootstrap sampling and > below is my example of function. > > Read a data , use some functions and use iteration to find the solution( > ie, convergence is reached). I want to use bootstrap approach to do it > several times (200 or 300 times) this whole process and see the > distribution of parameter of interest. > > Below is a small example that resembles my problem. However, I found out > all samples are the same. So I would appreciate your help on this case. > > #************************************** > rm(list=ls()) > xx <- read.table(textConnection(" y x > 11 5.16 > 11 4.04 > 14 3.85 > 19 5.68 > 4 1.26 > 23 7.89 > 15 4.25 > 17 3.94 > 7 2.35 > 17 4.74 > 14 5.49 > 11 4.12 > 17 5.92"), header=TRUE) > data <- as.matrix(xx) > closeAllconnections() > > Nt <- NULL > for (Ncount in 1:100) > { > y <- data[,1] > x <- data[,2] > n <- length(x) > > X <- cbind(rep(1,n),x) #covariate/design matrix > obeta<- c(1,1) #previous/starting values of beta > > nbeta <- c(0,0) #new beta > iter=0 > > while(crossprod(obeta-nbeta)>10^(-12)) > { > nbeta <- obeta > eta <- X%*%nbeta > mu <- eta > mu1 <- 1/eta > W <- diag(as.vector(mu1)) > Z <- X%*%nbeta+(y-mu) > XWX <- t(X)%*%W%*%X > XWZ <- t(X)%*%W%*%Z > Cov <- solve(XWX) > obeta <- Cov%*%XWZ > iter <- iter+1 > > cat("Iteration # and beta1= ",iter, nbeta, "\n") > } > > Nt[Ncount] <- nbeta[1,1] > } > Nt > summary(Nt) > #**************e***************************************** > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.