代码之家  ›  专栏  ›  技术社区  ›  Erdne Htábrob

与glmer的相互作用对比

  •  1
  • Erdne Htábrob  · 技术社区  · 7 年前

    model <- glmer(protest ~ factora*factorb*numeric+factora+factorb+numeric+1 + (1 + factor1|level1) + (1|level2), data=data, family=binomial(link='logit'))
    

    哪里 factora factorb numeric 是一个数值变量。

    因素 常数为3,介于 系数B (1-5)在数值范围内。

    我尝试了以下选择,但没有成功:

    library(psycho)
    get_contrasts(model, formula="factora:factorb:numeric", adjust="tukey")
    View(contrasts$contrasts) 
    

    这是可行的,但不幸的是结果是 数字 不变且仅变化 因素 系数B . 因此,它没有回答我的问题。

    library(multcomp)
    test = glht(model,linfct=mcp("factora:factorb:numeric"="Tukey"))
    

    这就产生了

    Error in mcp2matrix(model, linfct = linfct) : 
      Variable(s) ‘factora:factorb:numeric’ have been specified in ‘linfct’ but cannot be found in ‘model’! 
    

    不考虑我指定交互的方式,也不考虑其他诸如 get_contrasts

    我也试过:

    library(emmeans)
    contrast(m.3[[2]], interaction = c("factora", "factorb", "numeric"))
    

    但这并不支持glmer。

    有什么想法吗?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Russ Lenth    7 年前

    这里有几个问题让你绊倒了。

    emtrends() 艾美 包可以帮助您估计这些不同的坡度。

    interaction 论证 emmeans::contrast() 需要一个 类型 使用对比度,例如。, "pairwise" . 应用它们的因素是 emmGrid 第一个参数中的对象。

    emt <- emtrends(model, ~ factora*factorb, var = "numeric")
    emt    # list the estimated slopes
    
    contrast(emt, interaction = "consec")
        # obtain interaction contrasts comparing consecutive levels of the two factors