在审查回归模型中计算自回归项和sigma的标准误差

时间:2019-07-03 12:12:32

标签: r confidence-interval standard-error

我已经使用carx包在R中安装了经过审查的回归模型。 我正在使用的数据有130个观测值

 head(SAdata)
 # A tibble: 6 x 10
  CC   lcl   Dum    ci   CPI    LI      FDI     FPI       OI Inflows
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl>    <dbl>   <dbl>    <dbl>   <dbl>
1  0.617   2.00     0  2.00  4.94  23.3 -0.207   -0.0320 -0.924   -1.16  
2  0.410   2.00     0  2.00  2.92  20.5 -0.246   -0.128   0.0749  -0.299 
3  0.196   2.00     0  2.00  4.26  17.2 -0.177   -0.0763 -0.482   -0.736 
4  0.0518  2.00     0  2.00  5.90  15.5  0.00493 -0.313  -1.59    -1.90  
5 -0.255   2.00     0  2.00  3.29  14.8 -0.0187  -0.200  -1.38    -1.59  
6 -0.392   2.00     0  2.00  4.43  14   -0.00292 -0.0860 -0.00519 -0.0941
> dim(SAdata)
[1] 130  10


library(carx)
SAmodel <- carx(y=SAdata$CC, x=SAdata[,c("CPI","LI","FDI","FPI", "OI")], lcl=1.996866, p=2, CI.compute = FALSE, CI.level = 0.95)

summary(SAmodel)
 Call:
carx.default(y = SAdata$CC, x = SAdata[, c("CPI", "LI", "FDI", "FPI", "OI")], lcl = 1.996866, p = 2, CI.compute = FALSE, CI.level = 0.95)


Coefficients:
  Estimate
CPI     0.0804
LI     -0.0088
FDI    -0.0395
FPI    -0.0166
OI      0.0488
AR1     1.6324
AR2    -0.7097
sigma   0.4286

AIC:
[1] -72.92045

但是我得到的只是估计值而没有置信区间,此包中的置信区间是通过自举计算的,这需要花费大量时间,当我将参数IC.compute = T设置为1000次迭代时(所读取的内容是迭代次数最少的内容),花了整整一天的时间才完成。因此,我尝试手动计算每个系数的标准误差,但是找不到用于计算自回归项和sigma的标准误差的方法。

这就是我尝试过的

#Calculating the residuals of the fitted model
SAres = residuals(SAmodel,type="raw")
# Find the sum of the squared residuals
rss <- sum(SAres^2)
# And use that to find the estimate of sigma^2, commonly called S
S <- sqrt(rss / (length(SAres) - length(SAmodel$coefficients)))
# Make the X matrix; a column of 1s for the intercept and one for each variable
X <- cbind(rep( nrow(SAdata)), SAdata$CPI, SAdata$LI,SAdata$FDI, SAdata$FPI, 
SAdata$OI)
# Multiply matrices using %*%, transpose them with t(),
# and invert them with solve(); and directly apply the formula above with:
std.errors <- S * sqrt(diag(solve(t(X) %*% X)))

std.errors
[1] 0.001232184 0.037669933 0.010483153 0.068843648 0.040779940 0.063888636

我不包括自回归项(AR1,AR2)和sigma,因为它们的计算基于响应变量。如何获得这些参数的标准误差?

我需要计算标准误差,以便以后可以计算每个系数的置信区间。

任何帮助深表感谢

0 个答案:

没有答案