Hi.

I am trying to reproduce output from the PROC MIXED procedure using R.

proc mixed data=m;

class name y country;

model y = name|year;

repeated / type=ar(1) sub=country;

run;

Does anybody know what I'm doing in R?

Thank you in advance.

Hi.

I am trying to reproduce output from the PROC MIXED procedure using R.

proc mixed data=m;

class name y country;

model y = name|year;

repeated / type=ar(1) sub=country;

run;

Does anybody know what I'm doing in R?

Thank you in advance.

you are doing a linear mixed model.

Here is a guide I googled on R, that seems a good place to start.

A Practical Guide to Mixed Models in R (tufts.edu)

1 Like

I don't know the SAS syntax well enough, so I cannot help in direct translation, but I recognize that this is not a mixed model (MIXED), but rather a model for repeated observations (REPEATED), with only fixed effects (contrary to its name, MMRM) and fits a marginal (population-average) model via GLS (generalized least square). GLS is the SAS way to handle the REPEATED clause.

You can fit such model using the nlme::gls().

Now, if the model is like this:

response: Y

fixed terms: name, year and their interaction

then it's something like: `gls(y ~ year*name, correlation = corAR1(form = ~ 1 | country), weights = varIdent(form = ~ 1 | year), data=m, method = "REML")`

year*name translates to: year + name + year:name

the weights parameter handles heteroscedasticity at each time point.

correlation is self describing

Here country is the grouping cluster, for which you have repeated observations, right?

As I said I'm not sure about the exact translation from SAS to R.

The problem will be also in the degrees of freedom. For REPEATED SAS will probably use BETWITHIN.

GLS will probably use the residual ones.

You may specify DDFM=SATTERTHWAITE and try getting the same with additional R package called "emmeans" (LS-means, called in R EM-means for estimated marginal means). It gives Satterthwaite for a GLS fitted model, either exact or approximate (if estimation of the var-cov fails). Then the results may be closer between SAS and R.

You may also try the "parameters" package which seems to handle BETWITHIN degrees of freedom for the nlme, but I don't know if it handles gls().

In general it's difficult to obtain exactly same results between SAS and R and you'll need some experimenting.

2 Likes

Hi,

I have gathered some I hope useful links for you to look at:

https://stackoverflow.com/questions/30878050/equivalent-of-sas-proc-mixed-in-r

https://stackoverflow.com/questions/44003350/mixed-model-repeated-measures-from-sas-to-r

https://www.youtube.com/watch?v=Awo_Otgs57g&t=182s

I hope this helps but please have a look at @Frequentist detailed explanation from the expert.

2 Likes

Thank you for your kind explanation.

Thank you for your detailed and kind explanation.

Your advice was very helpful.

I have one more question.

How do I change the name and year as categorical variables?

Thank you in advance.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.