# R: multiple linear regression model and prediction model

Starting from a linear model1 = lm(temp~alt+sdist) i need to develop a prediction model, where new data will come in hand and predictions about temp will be made.

I have tried doing something like this:

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

However, i am not sure this is the right way. What i would like to know here is, if this is the right way to go in order to make prediction about temp. Also i am a bit confused when it comes to the newdataset. Which values should be filled in etc.?

newdata should contain a column for each of your predictive variables, alt and sdist. (Any variables except the one you're predicting.) For example:
newdata = data.frame(alt = newAltVector, sdist = newSdistVector)

predictions will then contain a fitted y value for each new x. In the below, black dots represent training data, and the blue dots represent predicted values.
Whether that's the right way to predict temp depends on how well a linear model approximates the relationship between variables. Try this intro to evaluating a linear model in R.
• Well your answer helped a lot. Thanks for the link too. By the way how did you plotted the using predictor and predicted variables? – Murania Mar 24 '14 at 21:31