如何解决想要使用 gls 获取系数、s.e. 和 t-stat,但它们没有出现在输出中
我无法显示回归系数。它们在应该出现的部分中似乎是空白的。
这是我正在运行的代码:
gls <- gls(prevm_adh ~ factor(alter_relation) + factor(group) + factor(sa.y) + factor(visno) + factor(female),corr = corCompSymm(form = ~ 1 | EgoID),data = ego_alter_data_regressions,# compound symmetry
method = "ML",na.action = na.omit,control = list(singular.ok = TRUE))
summary(gls)
这是我得到的输出,但系数,s.e.并且 t-stats 没有出现。
Generalized least squares fit by maximum likelihood
Model: prevm_adh ~ factor(alter_relation) + factor(group) + factor(sa.y) + factor(visno) + factor(female)
Data: ego_alter_data_regressions
Correlation Structure: Compound symmetry
Formula: ~1 | EgoID
Parameter estimate(s):
Rho
0.6392145
Coefficients:
Correlation:
(Intr) fc(_)F fc(_)O fctr(g)2 fct()3 fc(.)1 fctr(v)1 fctr(v)2
factor(alter_relation)Friend -0.048
factor(alter_relation)Other -0.023 0.191
factor(group)2 -0.089 -0.002 -0.001
factor(group)3 -0.223 0.005 0.002 0.241
factor(sa.y)1 -0.322 -0.005 -0.004 -0.050 -0.465
factor(visno)1 -0.070 0.000 0.000 0.012 -0.003 -0.014
factor(visno)2 -0.068 0.000 0.001 0.013 -0.001 -0.008 0.574
factor(female)1 -0.706 0.005 0.002 -0.283 0.128 -0.043 -0.001 -0.002
Standardized residuals:
Min Q1 Med Q3 Max
-3.4338769 -0.1820022 0.1299327 0.6680821 1.6381633
Residual standard error: 30.75149
degrees of freedom: 23765 total; 23756 residual
系数的标题显示出来,它们通常应该列在那里,但它们没有。我不知道这有什么问题。
解决方法
我无法重现您的错误。看起来您的数据中的某些异常导致了问题。您能否尝试调整此示例,使其提出您所看到的问题?
library(nlme)
set.seed(436456)
ego_alter_data_regressions <- data.frame(
alter_relation = factor(rep(c("Friend","Other"),each = 12)),group = factor(rep(1:3,times = 8)),ego_id = factor(rep(1:12,times = 2)),female = factor(0:1),prevm_adh = rpois(24,2))
gls1 <- gls(prevm_adh ~ factor(alter_relation) + factor(group) + factor(female),corr = corCompSymm(form = ~ 1 | ego_id),data = ego_alter_data_regressions,# compound symmetry
method = "ML",na.action = na.omit,control = list(singular.ok = TRUE))
sg1 <- summary(gls1)
sg1
# Generalized least squares fit by maximum likelihood
# Model: prevm_adh ~ factor(alter_relation) + factor(group) + factor(female)
# Data: ego_alter_data_regressions
# AIC BIC logLik
# 114.7237 122.9701 -50.36187
#
# Correlation Structure: Compound symmetry
# Formula: ~1 | ego_id
# Parameter estimate(s):
# Rho
# 0.1456311
#
# Coefficients:
# Value Std.Error t-value p-value
# (Intercept) 2.1250000 1.0610047 2.0028186 0.0597
# factor(alter_relation)Other 0.3333333 0.8411910 0.3962635 0.6963
# factor(group)2 0.0000000 1.1929986 0.0000000 1.0000
# factor(group)3 -0.1250000 1.1929986 -0.1047780 0.9177
# factor(female)1 0.1666667 0.9740793 0.1711017 0.8660
#
# Correlation:
# (Intr) fc(_)O fct()2 fct()3
# factor(alter_relation)Other -0.396
# factor(group)2 -0.562 0.000
# factor(group)3 -0.562 0.000 0.500
# factor(female)1 -0.459 0.000 0.000 0.000
#
# Standardized residuals:
# Min Q1 Med Q3 Max
# -1.32345932 -0.62496690 -0.07352552 0.35712394 2.85699155
#
# Residual standard error: 1.983438
# Degrees of freedom: 24 total; 19 residual
summary
的输出是一个类似列表的对象,这意味着您可以使用 $
提取摘要的组成部分。
names(sg1)
# [1] "modelStruct" "dims"
# [3] "contrasts" "coefficients"
# [5] "varBeta" "sigma"
# [7] "apVar" "logLik"
# [9] "numIter" "groups"
# [11] "call" "method"
# [13] "fitted" "residuals"
# [15] "parAssign" "na.action"
# [17] "corBeta" "tTable"
# [19] "BIC" "AIC"
sg1$coefficients
# (Intercept)
# 2.125000e+00
# factor(alter_relation)Other
# 3.333333e-01
# factor(group)2
# 3.896296e-16
# factor(group)3
# -1.250000e-01
# factor(female)1
# 1.666667e-01
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。