# estimating prediction error through bootstrap and cross validation for hormone data z<- c(99, 152, 293, 155, 196, 53, 184, 171, 52, 376, 385, 402, 29, 76, 296, 151, 177, 209, 119, 188, 115, 88, 58, 49, 150, 107, 125) l<- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0) length(z) length(l) p <- t(rbind(z,l)) # rbind combinds two vectors into rows # t give the transpose. dim(p) y<- c(25.8, 20.5, 14.3, 23.2, 20.6, 31.1, 20.9, 20.9, 30.4, 16.3, 11.6, 11.8, 32.5, 32.0, 18.0, 24.1, 26.5, 25.8, 28.8, 22.0, 29.7, 28.9, 32.8, 32.5, 25.4, 31.7, 28.5) length(y) #c<- matrix(z , nrow = 27, ncol = 2, byrow =F) #y <- c(14, 16, 20, 18, 19) #x<- c(227, 8, 245, 7, 300, 8, 275, 6, 290, 8) #p<- matrix(x, nrow = 5, ncol = 2, byrow = T) #p #dim(p) theta.fit<- function (p, y){lsfit(p,y)} theta.predict<- function (fit, p){ cbind(1, z)%*%fit$coef } sq.err<- function(y, yhat) {(y-yhat)^2} fit.out<- theta.fit (p,y) fit.out #bootstrap result1<- bootpred(p,y,20,theta.fit,theta.predict,err.meas=sq.err) miss.clas<- function(y,yhat){1*(yhat!=y)} #cross validation result2<- crossval(p,y,theta.fit,theta.predict)