【问题标题】:Error: Coefficients: (4 not defined because of singularities) in R错误:R中的系数:(由于奇异性而未定义4)
【发布时间】:2015-05-12 03:02:22
【问题描述】:

我的代码中有一些错误,我无法弄清楚。 我有一个数据框“a”,带有:

row.names      GM      variance     stddev      skewness   correltomarket  DEratio
1   MMM     0.9785122   0.9998918   0.9999459   -1.049053   2.932738    0.07252799

现在,我需要使用以下代码为上述数据框找到一个线性模型

riskmodel <- lm(formula=((a$GM)~(a$variance)+(a$skewness)+
                         (a$correltomarket)+(a$DEratio)),data=a)

当我运行此代码时,我得到以下“风险模型”的摘要

Call:
lm(formula = ((a$GM) ~ (a$variance) + (a$skewness) + (a$correlationtomarket) + 
    (a$DEratio)), data = a)

Residuals:
ALL 1 residuals are 0: no residual degrees of freedom!

Coefficients: (4 not defined because of singularities)
                      Estimate Std. Error t value Pr(>|t|)
(Intercept)             0.9785         NA      NA       NA
a$variance                  NA         NA      NA       NA
a$skewness                  NA         NA      NA       NA
a$correlationtomarket       NA         NA      NA       NA
a$DEratio                   NA         NA      NA       NA

Residual standard error: NaN on 0 degrees of freedom

我不明白为什么,我会非常感谢任何帮助我的人。我不知道出了什么问题。

【问题讨论】:

  • lm 中,您不需要使用a$,因为您使用data= 提供数据。
  • 谢谢 :),我会记住的。 :)
  • @Pascal,知道为什么是 NA 吗?
  • 请参阅 Dason 的回答。你不能只用一个观察值来运行多元线性回归。
  • @Pascal,我已经看到了答案,但我不太明白。你能解释一下吗?谢谢!

标签: r dataframe lm


【解决方案1】:

您的 data.frame 中只有一个观察值。您不能仅通过一次观察来拟合具有 5 个参数的模型。您需要至少 6 个观测值才能拟合参数并估计方差。

【讨论】:

  • 对不起,我不太明白,你能解释一下吗?或可以在这里帮助我的链接?谢谢!
  • 非常感谢!这有帮助。
猜你喜欢
  • 1970-01-01
  • 2019-05-28
  • 2017-08-03
  • 2021-10-28
  • 2016-08-25
  • 1970-01-01
  • 1970-01-01
  • 2014-04-14
  • 2021-06-05
相关资源
最近更新 更多