[R] Weird LM behaviour
Jason Barnhart
jasoncbarnhart at msn.com
Fri May 19 22:01:00 CEST 2006
No, not weird.
Think of it this way. As you move point (0,2) to (1,2) the slope which was
0 is moving towards infinity. Eventually the 3 points are perfectly
vertical and so must have infinite slope.
Your delta-x is not sufficiently granular to show the slope change for
x-values very close to 1 but not yet 1, like 0.999999999. Note lm returns
NA when x=1.
As for the localized variation my guess is these are the artifact of having
3 data points.
-jason
----- Original Message -----
From: "Rense Nieuwenhuis" <r.nieuwenhuis at student.ru.nl>
To: <R-help at stat.math.ethz.ch>
Sent: Friday, May 19, 2006 11:51 AM
Subject: [R] Weird LM behaviour
> Dear R users,
>
> experimenting with the lm function in R, I've encountered some
> behaviour I don't understand with my limited knowledge of regression.
>
> I made a data-'set' of three measurements (see syntax below). Using
> lm (linear model) to fit the regression-line, I expected to find an
> intercept of 2.0 and a slope of 0, but in fact the slope is slightly
> below zero. Amazed by this behaviour, I decided to shift the
> measurements towards each other, create a model using lm and analyse
> the resulting slopes. Plotting these, I found that they are
> increasingly deviant from zero when the difference between the three
> values is smaller. More fascinating, some of the slopes seem to be
> relatively large in comparison with other resulting slopes (sort of
> outliers).
>
> How is this possible? Is this a rounding-problem or is it the way R
> creates the linear model? Using SPSS results in b-values of zero. I'm
> using R 2.3 on MacOS 10.4.6, on a G4 processor. The syntax I used is
> printed below.
>
> Any explanations of this behaviour are really appreciated.
>
> Rense Nieuwenhuis
>
> #--------------------------
>
> x <- c(0,1,1)
> y <- c(2,1,3)
> plot(x,y)
> b <- 1
> length <- 100
>
> for(i in 1:length) {
> x[1] <- i/length
> model <- lm(y~x)
> b[i] <- model$coefficients[2]
> }
>
> plot(b)
>
> #----------------
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list