[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    Re: [R] stats::lm has inconsistent output when adding constant to dependent variable
From:       Aleš Žiberna <aleszib () gmail ! com>
Date:       2019-10-03 7:35:21
Message-ID: CAOB2iXyg6QUX_NYfsReM8tJCtWqkFmozCmnQnUczcQTMExm40A () mail ! gmail ! com
[Download RAW message or body]

In one case they are exactly 0 and in the other they are almost zero. This
is the reason for different results.

Of course, they should be exactly the same, but this is due to some integer
values not being exactly represented as real values on binary computers.

Best,
Aleš Žiberna

On Fri, Sep 27, 2019 at 9:01 PM Rui Barradas <ruipbarradas@sapo.pt> wrote:

> Hello,
>
> Maybe FAQ 7.31?
>
> Check the residuals, they are all "zero" in both cases:
>
> fit0 <- lm(y~x)
> fit1 <- lm(1+y~x)
>
> # residuals
> table(resid(fit0))
> #
> # 0
> #30
>
> table(resid(fit1))
> #
> #-5.21223595241838e-16 -4.93038065763132e-31  3.12734157145103e-15
> #                    6                    23                     1
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 18:05 de 27/09/19, David J. Birke escreveu:
> > Dear R community,
> >
> > I just stumbled upon the following behavior in R version 3.6.0:
> >
> > set.seed(42)
> > y <- rep(0, 30)
> > x <- rbinom(30, 1, prob = 0.91)
> > # The following will not show any t-statistic or p-value
> > summary(lm(y~x))
> > #  The following will show t-statistic and p-value
> > summary(lm(1+y~x))
> >
> > My expected output is that the first case should report t-statistic and
> > p-value. My intuition might be tricking me, but I think that a constant
> > shift of the data should be fully absorbed by the constant and not
> > affect inference about the slope.
> >
> > Is this a bug or is there a reason why there should be a discrepancy
> > between the two outputs?
> >
> > Best,
> > David
> >
> > ______________________________________________
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic