Solved – R Multiple Linear Regression; plotting results

rregression

I'm trying to do some exploratory analysis on some weather. I'd like to do a multiple linear regression on my data and then plot the predicted value against the actual value. Here's where I've got so far:

data<-read.csv("Amsterdam.csv", header=TRUE)
data2<-data[SolarAltitude>0,]
data2.lm<-lm(DirectRadiation ~ DryBulbTemperature + RelHum
   +AtmosphericPressure, data=data2)
data.data.frame(data2,fitted.value=fitted(data2.lm),residual=resid(data2.lm)) 

If you could help, I would be very grateful,

Best Answer

The function fitted returns the fitted (predicted) values. To plot the fitted values against the actual values, you can use:

plot(data2$DirectRadiation, fitted(data2.lm))

This will produce a plot with the actual values on the horizontal axis and the fitted values on the vertical axis.

If the above code doesn't work due to missing data, you can try one of the following approaches:

 plot(fitted(data2.lm) + residuals(data2.lm), fitted(data2.lm))

 plot(data2.lm$model[[1]], fitted(data2.lm))