Open statasaurus opened 1 year ago
Hello @kaigu1990 we don't have a specific plan for this, but if you would like to add in the content I imagine it would be very helpful. Thank you 😃
there are examples of LSMeans calculations in the mmrm package repository documentation
Hi @statasaurus and @yonicd , Thanks for your advice.
After learning the mmrm
and emmeans
related documents, we can compute the least-square means, corresponding contrasts and hypothesis testing using functions in emmeans
.
First, we fit a MMRM model.
library(mmrm)
library(emmeans)
fit <- mmrm(
formula = FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID),
reml = TRUE, method = "Kenward-Roger", vcov = "Kenward-Roger-Linear",
data = fev_data
)
summary(fit)
And then compute the least-square means with corresponding CI.
ems <- emmeans(fit, ~ ARMCD | AVISIT)
confint(ems)
Suppose we want to answer the question that the null hypothesis is that treatment minus placebo equals zero. The contrast can be created below.
contr <- contrast(ems, adjust = "none", method = "pairwise")
contr
Suppose we would like to test the hypothesis that treatment is superior to placebo with a margin of 2
.
test(contr, null = 2, side = ">")
This is just a brief summary. I have also compared the above results with the SAS code below. If there is something wrong, please tell me.
proc mixed data=fev_data;
class ARMCD(ref='PBO') AVISIT RACE SEX USUBJID;
model FEV1 = RACE SEX ARMCD ARMCD*AVISIT / ddfm=KR;
repeated AVISIT / subject=USUBJID type=UN r rcorr;
lsmeans ARMCD*AVISIT / cl alpha=0.05 diff slice=AVISIT;
lsmeans ARMCD / cl alpha=0.05 diff;
lsmestimate ARMCD*AVISIT [1,1 4] [-1,2 4] / cl upper alpha=0.025 testvalue=2;
ods output lsmeans=lsm diffs=diff LSMEstimates=est;
run;
Just FYI: @stephenwaugh will be investigating further into MMRMs and updating these pages from Sept 2024 - July 2025.
@statasaurus Is there a plan to compare how SAS and R compute the LS mean in the MMRM? And moving forward, to do more specific scenarios, such as computing the LS mean in the non-inferiority or superiority trials.