[R] Predicted values from glm() when linear predictor is NA.

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Tue Aug 2 09:10:43 CEST 2022


>>>>> Rolf Turner 
>>>>>     on Thu, 28 Jul 2022 14:19:49 +1200 writes:

    > On Wed, 27 Jul 2022 18:25:23 -0700 David Winsemius
    > <dwinsemius using comcast.net> wrote:

    > <SNIP>

    >> The NA is most likely caused by aliasing, so some other
    >> combination of factors a perfect surrogate for every case
    >> with that level of the interaction.

    > <SNIP>

    > No, I think it's much simpler than that.  Essentially it
    > boils down to the fact that if y is 1:10 and x is
    > rep(1,10) then

    >     lm(y ~ x)

    > gives a slope estimate of NA.  As it clearly should.

*and*  predict() should surely *not* be NA, either, right ??

You can easily confirm with

 x <- rep(1,7); y <- 1:7; summary(fm <- lm(y~x))
 predict(fm)

which gives all '4'  (= mean(y))

Note that this *is* aliasing:  x is aliased with the intercept,
and it fits entirely your situation:

If a predictor variable is superfluous, i.e., more precisely, a
column of the X design matrix is an exact linear combination of
previous columns,
prediction is no problem at all and gives exactly what you'd get
if you omit that superfluous column/variable.

Are you sure this is not simply your situation?
Martin


    > cheers,
    > Rolf

    > -- 
    > Honorary Research Fellow Department of Statistics
    > University of Auckland Phone: +64-9-373-7599 ext. 88276



More information about the R-help mailing list