R 想要使用gls获得系数s.e.和t-stat,但它们没有显示在输出中
我很难让回归的系数显示出来。它们在应该出现的部分中似乎是空白的 以下是我正在运行的代码:R 想要使用gls获得系数s.e.和t-stat,但它们没有显示在输出中,r,regression,coefficients,R,Regression,Coefficients,我很难让回归的系数显示出来。它们在应该出现的部分中似乎是空白的 以下是我正在运行的代码: 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_regress
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)
显示了系数的标题,它们通常应该列在那里,但它们不是。我不知道这是怎么回事。我无法重现您的错误。看起来您的数据中的某些异常正在导致问题。你能试着调整这个例子,让它引起你看到的问题吗
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
感谢您尝试重新创建错误@csjcampbell。我想知道我显示结果的方式是否有错误。在控制台中,系数不会显示(就像上面为您显示的那样),但如果我向下滚动代码下方,它们会显示在数据帧中。我是R的新手,所以我只是学习了一些。与AIC、BIC相同-它们显示在“我的代码”下面的数据框中,但不显示在控制台输出中。@AliData您可以使用
$
尝试从摘要对象提取系数值
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
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