我在netlm()
包中使用sna
运行网络回归。所有结果都很好。但是,我找不到每个系数的标准误差。返回的模型对象中没有标准错误; summary()
也不会导出它们。有没有办法得到它们?
IV0 <- list(SEX, GRADE, YEAR)
M0 <- netlm(K1M, IV0, nullhyp = "qapspp", reps = 2000)
summary.default(M0) ## check structure of returned model object
# Length Class Mode
# coefficients 4 -none- numeric
# fitted.values 812 -none- numeric
# residuals 812 -none- numeric
# qr 4 qr list
# rank 1 -none- numeric
# n 1 -none- numeric
# df.residual 1 -none- numeric
# tstat 4 -none- numeric
# dist 8000 -none- numeric
# pleeq 4 -none- numeric
# pgreq 4 -none- numeric
# pgreqabs 4 -none- numeric
# nullhyp 1 -none- character
# names 4 -none- character
# intercept 1 -none- logical
M0 ## print model object
# OLS Network Model
# Residuals:
# 0% 25% 50% 75% 100%
# -0.3669251 -0.3376203 -0.3066127 0.6623797 0.7340360
# Coefficients:
# Estimate Pr(<=b) Pr(>=b) Pr(>=|b|)
# (intercept) 0.271072656 0.966 0.034 0.0605
# x1 0.009641084 0.602 0.398 0.8360
# x2 -0.031007609 0.169 0.831 0.3440
# x3 0.029304737 0.774 0.226 0.4660
# Residual standard error: 0.47 on 808 degrees of freedom
# Multiple R-squared: 0.002094 Adjusted R-squared: -0.001611
# F-statistic: 0.5651 on 3 and 808 degrees of freedom, p-value: 0.6382
summary(M0) ## print model summary
# Test Diagnostics:
# Null Hypothesis: qapspp
# Replications: 2000
# Coefficient Distribution Summary:
# (intercept) x1 x2 x3
#Min -3.15189 -4.84538 -3.08131 -2.75036
#1stQ -0.65506 -0.99759 -0.65075 -0.68183
#Median 0.01805 -0.09364 0.06947 -0.01831
#Mean 0.02510 -0.03473 0.03247 -0.01179
#3rdQ 0.69636 0.90936 0.72701 0.63639
#Max 3.29170 5.71549 2.71428 2.90498
答案 0 :(得分:3)
sna::netlm()
会计算这些标准错误,以便在$tstat
中返回t得分,但它不会显式返回这些值。但是,获得它们并不是一件容易的事。
回想一下:
t-score = coefficient / standard.error
由于报告了系数和t分数,您可以将此公式反转为standard.error:
standard.error = coefficient / t-score
因此,给定模型M0
,系数的标准误差只是:
with(M0, coefficients / tstat)
我的初步答案是从$qr
对象计算这些标准错误:
std_coef <- function (model) {
sigma2 <- sum(model$residuals ^ 2) / model$df.residual
Rinv <- backsolve(model$qr$qr, diag(model$rank))
sqrt(rowSums(Rinv ^ 2) * sigma2)
}
std_coef(M0)
此功能专为lmObject
返回的lm()
而设计。但由于netlm()
基于lm()
并且还返回$qr
对象,因此我们也可以将其用于netlm()
。
但是,一旦我意识到netlm()
返回t-score,我就会使用该快捷方式更新我的答案。
答案 1 :(得分:2)
在前面的答案的基础上,重要的是要记住QAP不使用标准误差来评估重要性 - 至少不是直接的。该过程首先通过OLS计算系数和标准误差,然后通过指定的排列过程(在本例中为“qapspp”)创建测试统计的分布。然后将初始OLS系数与该分布进行比较以评估显着性。假设您需要OLS回归中的标准误差,您可以简单地对独立矩阵和从属矩阵进行矢量化,并使用好的,老式的lm()
。
使用某些玩具网络,您可以看到它是如何工作的。
nets<-rgraph(25,3)
response<- nets[1,,]*2+nets[2,,]*5
fit <- netlm(response, nets, nullhyp="qapspp")
fit$coefficients
[1] -0.019743805 2.052129105 5.086171312 -0.003684872
#View the distribution of the third independent matrix
plot(density(fit$dist[,4]))
abline(v=fit$tstat[4])
现在,您可以使用lm()
和gvectorize()
ols <- lm(gvectorize(response) ~ gvectorize(nets[1,,]) +
gvectorize(nets[2,,]) + gvectorize(nets[3,,]))
比较两个模型的系数,看它们是否相同:
fit$coefficients
[1] -0.019743805 2.052129105 5.086171312 -0.003684872
as.numeric(ols$coefficients)
[1] -0.019743805 2.052129105 5.086171312 -0.003684872
使用summary(ols)
会产生标准错误。
然而,鉴于网络数据的性质,这些标准错误是不可靠的,Krackhardt(1988)和其他地方详细介绍了这些错误。它们不用于计算netlm()
的摘要输出中的p值。而是使用生成的分布。在该过程中使用标准误差来生成t统计量,但重要性取决于观察到的t-stat在生成分布中的位置,如上所示。