<$BlogRSDUrl$>

Sunday, September 28, 2008

For the first question in the second homework, I used the "lm" function in R to generate a linear regression model for the first 200 rows(response<-data[1:200,1], predictor<-data[1:200,2:16], linearmodel<-lm(response~predictor)), and then used the predict function to predict the missing values: predict(linearmodel,newdata) (newdata is 2~16 column of the last 33 lines). However, evrey time I ran the predict function, a warning message pops out.

'newdata' had 33 rows but variable(s) found have 200 rows.

I tried many times but cannot fix this problem. The R never gives me correct predictions but repeatly gives me the above warning and prints the fitted value for the training set.

How can I solve this problem?



newdata has to have exactly the same dimensions as the
original data that lm used. Here's a cleaner way to accomplish this:

myData <- read.table("BankSortedMissing.TXT", header=TRUE)
mylm <- lm(newAccounts~.,data=myData, subset=1:200)
predict(mylm,myData)[201:233]

This page is powered by Blogger. Isn't yours?