Skip to content

Basic question: why does a scatter plot of a variable against itself works like this?

1 message · Barry Rowlingson

#
Interestingly, fitting an LM with x on both sides gives a warning, and
then drops it from the RHS, leaving you with just an intercept:
Call:
lm(formula = x ~ x, data = d)

Coefficients:
(Intercept)
          4

Warning messages:
1: In model.matrix.default(mt, mf, contrasts) :
  the response appeared on the right-hand side and was dropped
2: In model.matrix.default(mt, mf, contrasts) :
  problem with term 1 in model.matrix: no columns are assigned

there's no numerical problem fitting a line through the points:

 > d$xx=d$x
 > lm(x~xx,data=d)

Call:
lm(formula = x ~ xx, data = d)

Coefficients:
(Intercept)           xx
  5.128e-16    1.000e+00

It seems to be R saying "Ummm did you really mean to do this? It's kinda dumb".

I suppose this could occur if you had a nested loop over all columns
in a data frame, fitting an LM with every column, and didn't skip if
i==j

Except of course it doesn't:

 - fit with two indexes set to one:
Call:
lm(formula = d[, i] ~ d[, j])

Coefficients:
(Intercept)       d[, j]
  5.128e-16    1.000e+00

- fit with two ones:
Call:
lm(formula = d[, 1] ~ d[, 1])

Coefficients:
(Intercept)
          4

Warning messages:
1: In model.matrix.default(mt, mf, contrasts) :
  the response appeared on the right-hand side and was dropped
2: In model.matrix.default(mt, mf, contrasts) :
  problem with term 1 in model.matrix: no columns are assigned

Obviously this can all be explained in terms of R (or lm's, or
model.matrix's) evaluation schemes, but it seems far from intuitive.

Barry
On Wed, Nov 6, 2013 at 4:59 PM, William Dunlap <wdunlap at tibco.com> wrote: