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!
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With