0
$\begingroup$

To reproduce

set.seed(1)
N <- 100
x <- rep(1, N)
covar <- matrix(rnorm(N * 10), N)
lm(x ~ covar)

Because of the intercept, I would expect this to be singular and not solvable. Instead, I just get very small values for the coefficients of covar.

Anyone knows a way around this?


Edit: what is singular is

model.matrix(~ ., data = cbind.data.frame(x, covar))

(first two columns are all 1s)

$\endgroup$
4
  • $\begingroup$ What matrix would you expect to be singular, covar$^T$covar? $\endgroup$
    – Dave
    Commented Feb 18, 2021 at 8:37
  • $\begingroup$ @Dave Please see my edit. $\endgroup$
    – F. Privé
    Commented Feb 18, 2021 at 8:54
  • 1
    $\begingroup$ You are make much out of nothing. (1) Inspect zapsmall(coefficients(lm(x ~ covar))). (2) Type summary(lm(x ~ covar)). Together these should fully answer your question. $\endgroup$
    – whuber
    Commented Feb 18, 2021 at 14:20
  • $\begingroup$ Yes, this is the solution I came up with (testing if residuals are almost 0). The problem is that you get an R2 of 50% when the outcome has no variation, that can be very misleading. $\endgroup$
    – F. Privé
    Commented Feb 19, 2021 at 7:23

1 Answer 1

1
$\begingroup$

I am not sure why this should not be solvable. You regress, as you point out, a constant on a constant, which is "generated" to affect the dependent variable with a coefficient of one, plus other variables which are generated in a way so as to have nothing to do with the dependent variable. So a unit coefficient on the constant term and zero coefficients for the rest seem precisely what to expect. That they are not exactly zero is numerical noise to me.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.