Reputation: 1389
Im using R and created a chart using ggplot2.
ggplot(Month.Data, aes(y=Measure, x=Samples)) +geom_point() + geom_smooth(method = "lm", se = FALSE)
I then create a regression so I can make some predicitions
regression <- lm(Samples ~ Measure, data = Month.Data)
I pass my data frame of "Measures" to the predict function
predict(regression, Measures)
I'd expect the predictions to be the same as if I used the regression line on the chart, but they aren't the same. Why would this be the case? Is there a setting in ggplot or is my expectation incorrect?
Upvotes: 1
Views: 1043
Reputation: 132706
ggplot(Month.Data, aes(y=Measure, x=Samples)) + ...
Here your y values are Measure
and your x values Samples
.
regression <- lm(Samples ~ Measure, data = Month.Data)
Here your y values are Samples
and your x values Measure
.
Those are different models and predictions will be different since OLS minimizes the sum of squared residuals in y direction.
Upvotes: 3