Skip to main content
1 of 2
Sean
  • 1.6k
  • 1
  • 19
  • 25

To illustrate the numerical stability issue mentioned by @cbeleites, here is an example from Simon Wood on how to "break" lm(). First we'll generate some simple data and fit a simple quadratic curve.

set.seed(1); n <- 100
xx <- sort(runif(n))
y <- .2*(xx-.5)+(xx-.5)^2 + rnorm(n)*.1
x <- xx+100
b <- lm(y ~ x+I(x^2))

plot(x,y)
lines(x, predict(b), col='red')

enter image description here

But if we add 900 to X, then the result should be pretty much the same except shifted to the right, no? Unfortunately not...

X <- x + 900
B <- lm(y ~ X+I(X^2))
plot(X,y)
lines(X, predict(B), col='blue')

enter image description here

Other algorithms can of course be "broken" in different ways with different examples.

Sean
  • 1.6k
  • 1
  • 19
  • 25