# R lm() solves a singular system without error

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)

• What matrix would you expect to be singular, covar$^T$covar?
– Dave
Commented Feb 18, 2021 at 8:37
• @Dave Please see my edit. Commented Feb 18, 2021 at 8:54
• 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.
– whuber
Commented Feb 18, 2021 at 14:20
• 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. Commented Feb 19, 2021 at 7:23