与em的对比第二差异

问题描述

我正在使用emmeans进行对比(例如,通过1st / ndnd差异测试交互效果)。

它涉及3个步骤:

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

虽然我可以执行第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,2,2),QES    = c(1,3,3),# Choice set   
                        Alt    = c(1,# Alt 1 or Alt 2 in  choice set 
                        Choice = c(0,1),# Dep variable.  if  Chosen (1) or not (0)
                        LOC    = c(0,# Indep variable per Choice set,binary categorical 
                        SIZE   = c(1,binary categorical 
                        gender = c(1,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)