r - 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?
解决方案
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)
推荐阅读
- systemc - 改变 SC_THREAD 中每个时钟姿态的信号
- sql-server - 从参数传递一个或多个值时,SSRS IIF 语句无法正常工作
- linux - 为什么 linux shell 中的“exit”命令不起作用?
- reactjs - 单击开发工具对其进行样式设置时如何不取消选择反应选择
- scala - 如何从另一列创建元组列?
- angular - 如何在 Angular 中使用自定义材质图标
- terraform - Terraform Planning 在计划更改时删除资源
- python - 如何将下拉列表的选定值更新到数据库
- html -
使用动态数据无法按预期工作 - vba - VBA根据单元格值将行剪切并粘贴到另一个工作表并删除空行