如何在 polr 有序 logit 模型的截距上测试 linearHypothesis?
How to test linearHypothesis on intercepts of polr ordered logit model?
我想测试有序 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
:
The default method will work with any model object for which the
coefficient vector can be retrieved by coef and the
coefficient-covariance matrix by vcov (otherwise the argument vcov.
has to be set explicitly).
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
如何正确定义 car::linearHypothesis
中的 hypothesis.matrix=
来测试截距?
或者,有人已经从头开始做过吗?
预期结果是(来自 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)
我们可以使用 car::linearHypothesis.default
来检验关于 "polr"
对象截距的假设。该方法有一个参数 coef.=
,我们可以用组合的 coefficients
和 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
我想测试有序 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
:
The default method will work with any model object for which the coefficient vector can be retrieved by coef and the coefficient-covariance matrix by vcov (otherwise the argument vcov. has to be set explicitly).
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
如何正确定义 car::linearHypothesis
中的 hypothesis.matrix=
来测试截距?
或者,有人已经从头开始做过吗?
预期结果是(来自 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)
我们可以使用 car::linearHypothesis.default
来检验关于 "polr"
对象截距的假设。该方法有一个参数 coef.=
,我们可以用组合的 coefficients
和 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