0
hw4<-read.csv("***")
x<-hw4[,1] #length of x is n=100
y<-hw4[,2]
n<-100
x_new<-seq_len(20)
index<-sample(x,n,replace=T)
x_boot<-x[index]
y_boot<-y[index]
slr_classic<-lm(y_boot~x_boot)
classic_interval<-predict(slr_classic,newdata=data.frame(x=x_new),interval="confidence")

Here I want to use bootstrapping to creat a confifence interval. However it gives me error like this: "'newdata' had 20 rows but variables found have 90 rows" Having no idea what is going on>>>

  • When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. But one thing to note is that the names you use in `newdata=` must exactly match the variable names you used in your `lm` formula. – MrFlick Mar 12 '20 at 01:50
  • thanks a lot, I see what is going on. The last line of my code should be changed to predict(slr_classic,newdata=data.frame(x_boot=x_new),interval="confidence") – Siyang Cheng Mar 12 '20 at 01:58

0 Answers0