首页 > 解决方案 > 如何在 polr 有序 logit 模型的截距上测试线性假设?

问题描述

我想测试有序 logit 模型中截距的显着差异。

library(MASS)

house.plr <- polr(Sat ~ Infl + Type + Cont, weights = Freq, data = housing)
summary(house.plr)$coefficients
#           Value Std. Error   t value
# Infl -0.3907221 0.05856668 -6.671406
# Type  0.5654170 0.04921585 11.488515
# Cont  0.0998870 0.09008336  1.108829
# 1|2  -0.6937440 0.20773639 -3.339540
# 2|3   0.7906212 0.20701136  3.819216
# 3|4   2.0574730 0.21396779  9.615807

系数的假设检验工作正常(相关方法是car:::linearHypothesis.polr)。

library(car)
linearHypothesis(house.plr, hypothesis.matrix="Infl + Type + Cont")$`Pr(>Chisq)`[2]
# [1] 0.01679297

然而,测试拦截不起作用,即使拦截包含在vcov.

signif(vcov(house.plr), 3)
#           Infl      Type      Cont     1|2     2|3     3|4
# Infl  0.003430 -0.000269  0.000320 0.00666 0.00623 0.00595
# Type -0.000269  0.002420 -0.000442 0.00365 0.00410 0.00464
# Cont  0.000320 -0.000442  0.008120 0.01240 0.01250 0.01260
# 1|2   0.006660  0.003650  0.012400 0.04320 0.04130 0.04140
# 2|3   0.006230  0.004100  0.012500 0.04130 0.04290 0.04270
# 3|4   0.005950  0.004640  0.012600 0.04140 0.04270 0.04580

失败的尝试:

linearHypothesis(house.plr, "(1|2 - 2|3) + (2|3 - 3|4) = 0")
linearHypothesis(house.plr, "1|2")

或者,由于文档建议添加vcov

默认方法适用于可以通过 coef 检索系数向量和通过 vcov 检索系数 - 协方差矩阵的任何模型对象(否则必须显式设置参数 vcov.)。

linearHypothesis(house.plr, "1|2", vcov.=vcov(house.plr))

全部产出:

Error in constants(lhs, cnames_symb) : 
  The hypothesis "1|2" is not well formed: contains bad coefficient/variable names.
In addition: Warning message:
In constants(lhs, cnames_symb) : NAs introduced by coercion

我注意到系数和截距存储在不同的对象中,但这对我也没有多大帮助。

house.plr$coefficients
#       Infl       Type       Cont 
# -0.3907221  0.5654170  0.0998870 

house.plr$zeta
#        1|2        2|3        3|4 
# -0.6937440  0.7906212  2.0574730 

我如何正确定义hypothesis.matrix=for incar::linearHypothesis以测试截距?

或者,有人已经从头开始这样做了吗?

预期结果是(来自Stata):

 ( 1)  [cut1]_cons - 2*[cut2]_cons + [cut3]_cons = 0

           chi2(  1) =    6.53
         Prob > chi2 =    0.0106

数据:

data(housing, package="MASS")
housing$Sat <- as.factor(1:4)
housing[2:5] <- lapply(housing[2:5], as.integer)

标签: rregressionhypothesis-test

解决方案


我们可以使用 来检验关于"polr"对象截距的假设car::linearHypothesis.default。该方法有一个参数coef.=,我们可以使用组合的coefficientsand来提供它zetas,从而使我们与已经正确存在的 对应vcov。我们hypothesis.matrix=定义为矩阵。

coef.ext <- with(house.plr, c(coefficients, zeta))

M <- matrix(c(0, 0, 0, 1, -2, 1), nrow=1, 
            dimnames=list('1|2 - 2*(2|3) + 3|4 = 0', names(coef.ext)))

car::linearHypothesis.default(house.plr, hypothesis.matrix=M, coef.=coef.ext)
# Re-fitting to get Hessian
# 
# Linear hypothesis test
# 
# Hypothesis:
# 1|2 - 2 2|3  + 3|4 = 0
# 
# Model 1: restricted model
# Model 2: Sat ~ Infl + Type + Cont
# 
#   Res.Df Df  Chisq Pr(>Chisq)  
# 1   1676                       
# 2   1675  1 6.5269    0.01063 *
# ---
# Signif. codes:  
# 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

推荐阅读