在polr中使用Hessian计算方差 - 协方差矩阵

时间:2016-03-30 20:32:55

标签: r logistic-regression hessian-matrix

我正在尝试使用函数的Hessian矩阵输出来计算polr模型的方差 - 协方差矩阵。这是来自polr帮助文件中的示例。

house.plr <- polr(Sat ~ Infl + Type + Cont, weights = Freq, data = housing, Hess=TRUE)
house.plr
vcov(house.plr)

收率:

InflMedium      InflHigh TypeApartment    TypeAtrium   TypeTerrace      ContHigh  Low|Medium Medium|High
InflMedium     0.0109522057  0.0058388698 -0.0001186328  0.0003571197  0.0001194372  0.0005232715 0.005775204 0.006214155
InflHigh       0.0058388698  0.0161686862 -0.0011185535 -0.0005789764 -0.0002820811  0.0014699005 0.005527505 0.006480153
TypeApartment -0.0001186328 -0.0011185535  0.0142177040  0.0096212170  0.0096814809 -0.0013601564 0.008675546 0.008249148
TypeAtrium     0.0003571197 -0.0005789764  0.0096212170  0.0240787651  0.0097933321 -0.0019949511 0.008588096 0.008323855
TypeTerrace    0.0001194372 -0.0002820811  0.0096814809  0.0097933321  0.0229480160 -0.0020860814 0.008860681 0.008043844
ContHigh       0.0005232715  0.0014699005 -0.0013601564 -0.0019949511 -0.0020860814  0.0091270890 0.004438238 0.004703586
Low|Medium     0.0057752039  0.0055275049  0.0086755464  0.0085880959  0.0088606811  0.0044382384 0.015586835 0.014367825
Medium|High    0.0062141551  0.0064801526  0.0082491485  0.0083238553  0.0080438438  0.0047035861 0.014367825 0.015743208

当我采用Hessian的逆时,我得到相同的矩阵,除了最后一行和列,它对应于Medium | High截距。

(solve(house.plr$Hessian))

收率:

 InflMedium      InflHigh TypeApartment    TypeAtrium   TypeTerrace      ContHigh   Low|Medium   Medium|High
InflMedium     0.0109522057  0.0058388698 -0.0001186328  0.0003571197  0.0001194372  0.0005232715  0.005775204  0.0003698475
InflHigh       0.0058388698  0.0161686862 -0.0011185535 -0.0005789764 -0.0002820811  0.0014699005  0.005527505  0.0008026733
TypeApartment -0.0001186328 -0.0011185535  0.0142177040  0.0096212170  0.0096814809 -0.0013601564  0.008675546 -0.0003592705
TypeAtrium     0.0003571197 -0.0005789764  0.0096212170  0.0240787651  0.0097933321 -0.0019949511  0.008588096 -0.0002226414
TypeTerrace    0.0001194372 -0.0002820811  0.0096814809  0.0097933321  0.0229480160 -0.0020860814  0.008860681 -0.0006882434
ContHigh       0.0005232715  0.0014699005 -0.0013601564 -0.0019949511 -0.0020860814  0.0091270890  0.004438238  0.0002235743
Low|Medium     0.0057752039  0.0055275049  0.0086755464  0.0085880959  0.0088606811  0.0044382384  0.015586835 -0.0010271027
Medium|High    0.0003698475  0.0008026733 -0.0003592705 -0.0002226414 -0.0006882434  0.0002235743 -0.001027103  0.0018418271

如果我然后尝试使用Hessian导出的方差 - 协方差矩阵sqrt(diag(solve(house.plr$Hessian)))导出系数的标准误差,我最终会得到中等|高截距的标准误差的不同估计,我会来自summary(house.plr)。有人能解释一下这里发生了什么吗?

编辑:下面的aosmith评论提供了这个问题的简单答案,即vcov.polr不仅仅返回逆Hessian,而且还涉及估计的阈值。我的混淆,其解释可能对其他人有用,源于这样一个事实,即在调查包中从有序逻辑函数vcov返回的对象上使用svyolr返回一个不考虑的矩阵估计的阈值。似乎vcov.svyolr只是返回Hessian的逆,这不足以在有序逻辑模型中导出方差 - 协方差矩阵(如果我错了,有人请纠正我)。当我尝试在进一步分析中使用它时,它确实让我陷入困境。 (我最终通过窃取来自summary.svyolr的代码解决了这个问题,该代码计算了正确的vcov以确定标准错误。)

为了表明我的意思,我继续上面的代码,重新格式化上面的数据集,以便svyolr可以使用它,然后尝试使用'vcov'提取vcov矩阵:

#Formatting
  housing.long<-expand.table(housing, freq="Freq") 
  housing.long$Sat<-ordered(housing.long$Sat,     levels=c("Low","Medium","High"))
  housing.long$Infl<-relevel(housing.long$Infl,ref="Low")
  housing.long$Type<-relevel(housing.long$Type,ref="Tower")
  housing.long$Cont<-relevel(housing.long$Cont,ref="Low")
#create svy objecct
house.plrsvy <- svydesign(ids=~1, data=housing.long)
#store model
house.plrsvy <-svyolr(Sat ~ Infl + Type + Cont, design=house.plrsvy)

vcov(house.plrsvy) [c(2,1,3,4,5,6,7,8),c(2,1,3,4,5,6,7,8)] #reording so it matches the matrix above

这会返回一个矩阵,该矩阵可以与上面vcov(house.plr)返回的矩阵形成对比,请注意最后一行和最后一列:

                 InflMedium      InflHigh TypeApartment    TypeAtrium   TypeTerrace      ContHigh   Low|Medium   Medium|High
InflMedium     0.0107386871  0.0056386668 -0.0002981046 -0.0001050978 -0.0002336774  0.0004818157  0.005346583  0.0003733560
InflHigh       0.0056386668  0.0165482681 -0.0010957497 -0.0003494497 -0.0002874101  0.0012244473  0.005220762  0.0008554517
TypeApartment -0.0002981046 -0.0010957497  0.0146171435  0.0099883268  0.0100760460 -0.0011474964  0.009094801 -0.0003656346
TypeAtrium    -0.0001050978 -0.0003494497  0.0099883268  0.0234161270  0.0102936420 -0.0020927259  0.008830475 -0.0003345245
TypeTerrace   -0.0002336774 -0.0002874101  0.0100760460  0.0102936420  0.0231356022 -0.0023225443  0.008963416 -0.0006818656
ContHigh       0.0004818157  0.0012244473 -0.0011474964 -0.0020927259 -0.0023225443  0.0092707384  0.004737418  0.0001668623
Low|Medium     0.0053465831  0.0052207623  0.0090948014  0.0088304752  0.0089634162  0.0047374180  0.015934585 -0.0010762218
Medium|High    0.0003733560  0.0008554517 -0.0003656346 -0.0003345245 -0.0006818656  0.0001668623 -0.001076222  0.0018436991

0 个答案:

没有答案