R: multiple linear regression model and prediction model -


starting linear model1 = lm(temp~alt+sdist) need develop prediction model, new data come in hand , predictions temp made.

i have tried doing this:

model2 = predict.lm(model1, newdata=newdataset) 

however, not sure right way. know here is, if right way go in order make prediction temp. bit confused when comes newdataset. values should filled in etc.?

i putting comments answer.

1) can use predict rather predict.lm predict know input of class lm , right thing automatically.

2 newdataset should data.frame same variables original predictors - in case alt , sdist.

3) if bringing in data using read.table default create data.frame. assumes new data has columns named alt , sdist can do:

newdataset<-read.table(whatever) newpredictions<- predict(model1, newdata=newdatset) 

4) after have done if want check predictions - can following

summary(model1) 

this give intercept , coefficients alt , sdist newdataset[1,] should give alt , sdist values first row, can change 1 in bracket row want. use information summary(model1) calculate predicted value should using method trust.

finally use newpredictions[1] predict() gave first row (or change 1 other row)

hopefully should work out.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -