【发布时间】:2020-12-21 17:43:20
【问题描述】:
我不明白为什么 R 包“nlme”中的 lmList() 无法识别用于按组估计 WLS 模型的 weights 参数。
这是我的示例数据:
obs cusip DLogPrice DQSize error.var
1 2 000361AH8 0.657 -1150000 1.02
2 3 000361AH8 0.268 300000 0.945
3 4 000361AH8 -7.18 -1050000 1.28
4 5 000361AH8 0.500 -1100000 0.947
5 6 000361AH8 -0.509 -847000 0.970
6 7 000361AH8 -0.126 2847000 0.935
7 8 000361AH8 0 0 0.705
8 9 000361AH8 -0.144 -105000 0.825
9 10 000361AH8 0.144 105000 0.828
10 11 000361AH8 -0.144 -200000 0.825
11 12 000361AH8 0.431 570000 0.946
12 13 000361AH8 -0.287 -370000 0.825
13 14 000361AH8 0.882 -600000 0.961
14 15 000361AH8 -0.217 600000 0.925
15 2 000361AK1 -0.155 3000000 1.02
16 3 000361AK1 0.000104 14000 0.945
17 4 000361AK1 -0.182 -2014000 1.28
18 5 000361AK1 0.182 -2500000 0.947
19 6 000361AK1 -1.58 2200000 0.970
20 7 000361AK1 0.132 600000 0.935
21 8 000361AK1 1.12 -1300000 0.705
22 9 000361AK1 0.152 2000000 0.825
23 10 000361AK1 -1.10 200000 0.828
24 11 000361AK1 -0.0658 -2400000 0.825
25 12 000361AK1 0.142 1085000 0.946
26 13 000361AK1 -0.470 -1385000 0.825
27 14 000361AK1 0.228 3000000 0.961
28 15 000361AK1 -0.256 629000 0.925
估计一个简单的lm() WLS 会产生这些估计
> lm(DLogPrice ~ DQSize , weights = 1/error.var, data=test.data)
Call:
lm(formula = DLogPrice ~ DQSize, data = test.data, weights = 1/error.var)
Coefficients:
(Intercept) DQSize
-1.913e-01 7.096e-09
使用 lmList() 按组运行它 cusip 不使用 weights 也可以:
> lmList(DLogPrice ~ DQSize | cusip, data=test.data)
Call:
Model: DLogPrice ~ DQSize | cusip
Data: test.data
Coefficients:
(Intercept) DQSize
000361AH8 -0.3788868 4.171895e-07
000361AK1 -0.1163497 -7.162274e-08
Degrees of freedom: 28 total; 24 residual
Residual standard error: 1.498528
但同时按组 cusip 和 weights 运行 lmList() 不起作用:
> lmList(DLogPrice ~ DQSize | cusip, weights = 1/error.var, data=test.data)
lmList 中的错误(DLogPrice ~ DQSize | cusip, , weights = 1/error.var, data = test.data): 未使用的参数(权重 = 1/error.var)
对我做错了什么有什么想法吗?
【问题讨论】:
-
nlme的lmList没有权重参数,也许你想使用lme4::lmList -
谢谢。我确实使用了 nmle。