[Rd] rnorm is not truly random used in the lm function

Victor Tian tianxu03 at gmail.com
Thu Aug 3 15:49:57 CEST 2017

To whom it may concern,

I happened to run the following R code just to check the layout of the
output, but found that the code doesn't work the way I thought it should

> lm(rnorm(100) ~ rnorm(100))

lm(formula = rnorm(100) ~ rnorm(100))


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

It appears that rnorm(100) produces the same array of numbers on both sides
of the ~ sign.

It can be further verified by having the same error message if we do x <-
rnorm(100) and lm(x ~ x).

I would expect the two rnorm(100) functions in the lm function return two
different arrays of numbers, but am open to hear reasons from the other


*Xu Tian*

	[[alternative HTML version deleted]]

More information about the R-devel mailing list