Using R’s in-built dataset “stackloss”, develop a 95% prediction interval of the stack loss if the air flow is 70, water temperature is 22 and acid concentration is 80.
We apply the lm() function to a formula that describes the variable stack.loss by the variables Air.Flow, Water.Temp and Acid.Conc.
We then save the linear regression model in a new variable, say, stacklosslm
Now we store the values of variables (for which we need to make prediction) inside a new data frame, say, stockpredict.
> stockpredict = data.frame(Air.Flow=70, Water.Temp=22, Acid.Conc.=80)
Now apply the predict() function and set the predictor variable in the stockpredict argument.
Also set the interval type as “predict”, that uses 0.95 confidence level as default.
26.50163 18.61037 34.3929
At 95% confidence interval, the value of the stack loss is between 18.61 and 34.39 when Air Flow is 70, Water Temp is 22, and Acid Concentration is 80.
I hope this tutorial was useful and easy to understand to work on R for prediction using MLR model.