首页 > 解决方案 > lm() standard coefficient estimate is NA but covariates are not linearly dependent in R

问题描述

x <- matrix(c(rep(1,11),rep(0,8),rep(1,3),rep(0,8),rep(1,2)),ncol = 4)
y <- matrix(c( 10,11.4,8.5,11.2,11.9,10.7,7.5,11.2),ncol = 1)
model <- lm(y~x[,c(2,3,4)])
summary(model)

The above code gives NA for 3rd coefficient.Is it because in the model intercept is also taken into account and then the third coefficient can be written as linear combination of intercept and first 2 matrices?

标签: rmatrixlinear-regression

解决方案


Yes, if you want to get estimates for all three variables, you need to omit the intercept. This can be achieved as follows:

model <- lm(y~x[,c(2,3,4)]-1)
summary(model)

推荐阅读