simr icon indicating copy to clipboard operation
simr copied to clipboard

Marginal means

Open pitakakariki opened this issue 2 years ago • 2 comments

Consider experiments with multiple treatments. Plan is to calculate marginal means and look for differences between treatments after false positive / multiple comparisons corrections.

May want to calculate e.g. "probability that any treatment is different from control"; "probability that there are any specific significant differences" etc.

pitakakariki avatar Sep 26 '22 21:09 pitakakariki

Hi @pitakakariki thanks for your work on this project!

I'm interested in the marginal means of the three way interaction (averaged over covariates and RE) and am using emmeans to accomplish this.

As far as I have managed, I can use simr to model a change in sample size (id) for the coefficient on the 3 way interaction. Is it/will it be possible to hone in on a specific estimated marginal mean in my power analysis? A 50% change on my 3 way interaction coefficient is hard to interpret as it stands.

Here's my current simr workflow:

lmer_1 <- lmer(log(dv) ~ intervention * region * timepoint + covar
 + (1 + covar + timepoint|id), data = df)

model1_n16_simr <- extend(lmer_1, along="id", n=16)
p_curve_treat <- powerCurve(model1_n16_simr, 
                            test=fixed("interventiontrt:regionB:timepointt2", "t"),
                            along="id", 
                            breaks = c(8, 10, 12, 14, 16))

Here's what my current emmeans analysis looks like:

lmer_1_emm <- emmeans::emmeans(lmer_1, ~intervention*region*timepoint,
                                   type = "response",
                                   sigma = sigma(lmer_1),
                                   bias.adj=TRUE)

contrast(regrid(lmer_1_emm, 
                sigma = sigma(lmer_1),
                bias.adj=TRUE),
         "pairwise", 
         simple = c("timepoint"))

Which gives us:

region = A, intervention = ctrl:
 contrast  estimate     SE  df z.ratio p.value
 t1 - t2  -1.84e-02 0.0407 Inf  -0.452  0.6515

region = B, intervention = ctrl:
 contrast  estimate     SE  df z.ratio p.value
 t1 - t2  -1.51e-02 0.0339 Inf  -0.444  0.6568

region = A, intervention = trt:
 contrast  estimate     SE  df z.ratio p.value
 t1 - t2   2.80e-02 0.0398 Inf   0.703  0.4821

region = B, intervention = trt:
 contrast  estimate     SE  df z.ratio p.value
 t1 - t2  -4.33e-06 0.0341 Inf   0.000  0.9999

Results are averaged over the levels of: covar 
Degrees-of-freedom method: inherited from asymptotic when re-gridding 

I'm interested in varying the sample size to see an estimate of -0.1 for region B, intervention trt, t1-t2. Intervention, region, and timepoints each have 2 levels.

Jsalas424 avatar Apr 14 '23 11:04 Jsalas424

Marginal mean features are a while away, I haven't thought too much about what they will look like.

For now, the best you can probably do with simr is to write a custom function that takes your model and returns the p-value you're interested in.

pitakakariki avatar Apr 15 '23 02:04 pitakakariki