contrast of contrast with emmeans(二阶差分)

contrast of contrast with emmeans (second differences)

我正在使用 emmeans 进行对比对比(即通过一阶/二阶差分来测试交互作用)。

它包括 3 个步骤:

  1. 估计意味着使用“emmeans”
  2. 使用“对”估计均值是否存在差异(第一个差异)
  3. 使用 ????
  4. 估计差异(第二个差异)是否存在差异

虽然我可以执行步骤 1 和 2(请参阅下面的 reprex 和虚构数据),但我卡在了步骤 3 上。提示?

(小插图here中显示的对比是针对替代功能形式的对比,这与我要测试的有所不同)


suppressPackageStartupMessages({
  library(emmeans)})

# create ex. data set.  1 row per respondent (dataset shows 2 resp). 
cedata.1 <- data.frame( id    =  c(1,1,1,1,1,1,2,2,2,2,2,2),    
                        QES    = c(1,1,2,2,3,3,1,1,2,2,3,3),   # Choice set   
                        Alt    = c(1,2,1,2,1,2,1,2,1,2,1,2),   # Alt 1 or Alt 2 in  choice set 
                        Choice = c(0,1,1,0,1,0,0,1,0,1,0,1),   # Dep variable.  if  Chosen (1) or not (0)
                        LOC    = c(0,0,1,1,0,1,0,1,1,0,0,1),   # Indep variable per Choice set, binary categorical 
                        SIZE   = c(1,1,1,0,0,1,0,0,1,1,0,1),   # Indep variable per Choice set, binary categorical 
                        gender = c(1,1,1,1,1,1,0,0,0,0,0,0)    # Indep variable per indvidual, binary categorical 
)


# estimate model
glm.model <- glm(Choice ~  LOC*SIZE, data=cedata.1, family = binomial(link = "logit"))

# estimate means (i.e.,  values used to calc 1st diff). 
comp1.loc.size <- emmeans(glm.model, ~ LOC * SIZE) 

# calculate 1st diff (and p value)
pairs(comp1.loc.size, simple = "SIZE")   # gives result I want
#> LOC = 0:
#>  contrast estimate   SE  df z.ratio p.value
#>  0 - 1       -1.39 1.73 Inf -0.800  0.4235 
#> 
#> LOC = 1:
#>  contrast estimate   SE  df z.ratio p.value
#>  0 - 1        0.00 1.73 Inf  0.000  1.0000 
#> 
#> Results are given on the log odds ratio (not the response) scale.

# calculate 2nd diff (and p value)
# ** the following gives the relevant values for doing the 2nd diff comparison (i.e., -1.39 and 0.00)...but how to make the statistical comparison?
pairs(comp1.loc.size, simple = "SIZE")
#> LOC = 0:
#>  contrast estimate   SE  df z.ratio p.value
#>  0 - 1       -1.39 1.73 Inf -0.800  0.4235 
#> 
#> LOC = 1:
#>  contrast estimate   SE  df z.ratio p.value
#>  0 - 1        0.00 1.73 Inf  0.000  1.0000 
#> 
#> Results are given on the log odds ratio (not the response) scale.

pairs(pairs(comp1.loc.size, simple = "SIZE"), by = NULL)