使用序数:: clm通过序数回归中的因子变量之间的多重比较来探测相互作用

时间:2018-02-12 00:23:25

标签: r statistics regression

我在下面模拟了一些涉及3(实验条件)x 3(政治联盟)双向互动的数据。我可以使用ordinal::clm()运行整个模型。我怎样才能得到所有的多重比较?或者,至少,economyrace对每个政治小组的控制条件的影响。我试图自动化这个,所以创建一个长对比矩阵是不可取的。 ordinal::clm()个对象与vcovcoefficients相关联,因此这应该是可能的。我没有使用glhtemmeans

代码

## prepare ----------
library(Hmisc)
library(ordinal)
set.seed(1839)
## gen dat ----------
democrats       <- cut2(c(rnorm(80), rnorm(80, .4), rnorm(80, .6)), g = 5)
unaffiliated    <- cut2(c(rnorm(80), rnorm(80), rnorm(80, .5)), g = 5)
republicans     <- cut2(c(rnorm(80), rnorm(80, -.5), rnorm(80)), g = 5)
outcome         <- factor(c(democrats, unaffiliated, republicans))
levels(outcome) <- c("very negative", "somewhat negative", "neutral", 
                     "somewhat positive", "very positive")
condition       <- c(rep("control", 80), rep("economy", 80), rep("race", 80))
condition       <- as.factor(rep(condition, 3))
party           <- factor(c(rep("democrats", 240), 
                            rep("unaffiliated", 240),
                            rep("republicans", 240)))
dat             <- data.frame(outcome, condition, party)
## crosstb ----------
xtabs <- lapply(levels(dat$party), function(i) {
  round(prop.table(table(
    dat$outcome[dat$party == i], dat$condition[dat$party == i]
  )), 2)
})
names(xtabs) <- levels(dat$party)
## analyze ----------
mod <- clm(outcome ~ condition * party, data = dat)
xtabs
summary(mod)

输出

$democrats

                    control economy race
  very negative        0.10    0.06 0.03
  somewhat negative    0.08    0.08 0.05
  neutral              0.08    0.07 0.05
  somewhat positive    0.03    0.06 0.11
  very positive        0.04    0.07 0.09

$republicans

                    control economy race
  very negative        0.05    0.11 0.03
  somewhat negative    0.07    0.07 0.07
  neutral              0.04    0.09 0.07
  somewhat positive    0.08    0.05 0.08
  very positive        0.09    0.02 0.09

$unaffiliated

                    control economy race
  very negative        0.07    0.08 0.05
  somewhat negative    0.08    0.08 0.05
  neutral              0.07    0.08 0.05
  somewhat positive    0.06    0.06 0.08
  very positive        0.06    0.04 0.10
formula: outcome ~ condition * party
data:    dat

 link  threshold nobs logLik   AIC     niter max.grad cond.H 
 logit flexible  720  -1130.74 2285.47 4(0)  1.92e-12 3.8e+02

Coefficients:
                                   Estimate Std. Error z value Pr(>|z|)    
conditioneconomy                     0.6492     0.2829   2.295 0.021725 *  
conditionrace                        1.2790     0.2820   4.535 5.77e-06 ***
partyrepublicans                     1.0089     0.2873   3.512 0.000444 ***
partyunaffiliated                    0.5064     0.2809   1.803 0.071371 .  
conditioneconomy:partyrepublicans   -1.7765     0.4038  -4.400 1.08e-05 ***
conditionrace:partyrepublicans      -1.1987     0.3998  -2.998 0.002714 ** 
conditioneconomy:partyunaffiliated  -0.9094     0.3968  -2.292 0.021905 *  
conditionrace:partyunaffiliated     -0.5367     0.3981  -1.348 0.177568    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Threshold coefficients:
                                Estimate Std. Error z value
very negative|somewhat negative  -0.8056     0.2060  -3.912
somewhat negative|neutral         0.2176     0.2026   1.074
neutral|somewhat positive         1.0791     0.2067   5.220
somewhat positive|very positive   2.1167     0.2176   9.727

使用glht

时出错
> glht(mod, mcp(condition = "Tukey"))
Error in linfct[[nm]] %*% C : 
  requires numeric/complex matrix/vector arguments

临时解决方案

这样可行,但不能更正多重比较:

lapply(levels(dat$party), function(i) {
  cfs <- summary(clm(outcome ~ condition * relevel(party, i), data = dat))$coef
  cfs[grepl("^[A-Za-z]+$", rownames(cfs)), ]
})

0 个答案:

没有答案