Ethan
Ethan

Reputation: 31

How do i translate PROC MIXED in SAS to R with gls? (MMRM, AR1)

I am trying to get the same result as sas with R but there seems to be some difficulties.

For example R: contras:2-1 AVISITN = 6: estimate is -1.81 and SE is 1.59

library(nlme)
library(emmeans) 
gls <- do.call("gls", list(data=data,
                           model=CHG~TRTPN+AVISITN+TRTPN*AVISITN+BASE+COUNTRY,
                           correlation=corAR1(form=~1|SUBJID),
                           weights=varIdent(form=~1|AVISITN), method="REML" )) 
emm <- emmeans(gls, specs=trt.vs.ctrl ~ TRTPN, at=list(AVISITN=c(6,7,8,9,10)),
               by = "AVISITN", level = 0.4) summary(emm) 

SAS: estimate is -1.2 and SE is 1.24

proc mixed data=data method=reml;
  class subjid avisit trtp country ;
  model chg = trtp avisit trtpavisit country base /CL SOLUTION DDFM=KR; repeated avisit / subject=subjid type=AR(1) r;
  lsmeans trtpavisit / PDIFF CL alpha=0.40;
  ODS output Diffs=diffs01 lsmeans=lsmeans01;
run;

I have very little experience in using R so is there a way to get the same result? Many many thanks!

Upvotes: 3

Views: 507

Answers (1)

Daniel Sabanes Bove
Daniel Sabanes Bove

Reputation: 125

with the new mmrm package this is easy, and you will get results very close to SAS results:

library(mmrm)
library(emmeans) 
fit <- mmrm(
  CHG ~ TRTPN + AVISIT + TRTPN * AVISIT + BASE + COUNTRY + ar1(AVISIT | SUBJID),
  data = data,
  method = "Kenward-Roger"
)
summary(fit)

Note that instead of a numeric AVISITN variable you should use the factor AVISIT variable with mmrm. And the emmeans code can be used identically.

Does that help?

Upvotes: 1

Related Questions