2
$\begingroup$

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.

$\endgroup$
1
  • 1
    $\begingroup$ You want the residuals as if your model was 1:1 ? But you are doing a regression between the observed and the simulated. why ? What do you want to do ? $\endgroup$
    – el Josso
    Jul 11 '16 at 7:32
2
$\begingroup$

The most obvious thing to do is to plot residuals vs predicted (i.e. simulated) - you can plot this directly, without reference to a program to fit regression.

However, if you want to use a regression to fit it, you need an intercept of 0 and an offset of simulated, if your program allows for an offset. (In R that's lm(observed~0,offset=simulated))

That fit can be used produce most of the usual diagnostic plots, but not all (leverage, for example, is 0, so the leverage based plots won't work).

$\endgroup$
1
  • $\begingroup$ This is exactly what I was looking for! $\endgroup$
    – Mike T
    Jul 11 '16 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.