This question is similar to this one, where I would like to plot the residuals, except that my residuals are known, since I'm simply comparing simulated and observed values with an expected 1:1 linear relationship.
For example, consider a data.frame subset:
sub <- data.frame(observed=c(-0.75, 0, 1.84, -0.33, -1.6),
simulated=c(-0.73644, 0.00422, 1.69897, 0.04321, -1.59478))
sub$residual <- with(sub, observed - simulated)
sub
observed simulated residual
1 -0.75 -0.73644 -0.01356
2 0.00 0.00422 -0.00422
3 1.84 1.69897 0.14103
4 -0.33 0.04321 -0.37321
5 -1.60 -1.59478 -0.00522
par(pty="s")
plot(simulated ~ observed, sub)
abline(0, 1) # expected 1:1 line
sub.lm <- lm(simulated ~ observed, sub)
abline(sub.lm, col="red") # the best-fit line is close to the 1:1
The wrong approach would be to inspect and plot the imperfect linear model fit:
plot(sub.lm) # these are useful plots, but slightly different than I would expect
resid(sub.lm) # and these are obviously different than calculated directly
1 2 3 4 5
-0.06967768 -0.03752067 -0.08096466 0.31321064 -0.12504764
How can I perform a similar analysis/plot with the known residuals from a perfect 1:1 linear model?
What I've tried so far is:
plot(residual ~ 1, sub)
But it isn't quite the same as plot(sub.lm)
from above.