# Longitudinal models in R and WINBUGS or JAGS

I've tried to use R to fit some longitudinal models, mostly via lmer and nlme packages. However, it seems that many standard models are lacking, such as antedependence models or factor analytic models for covariance matrices. These models are readily available in SAS.

Would anyone recommend other packages for the job in R? I don't really care if I use to work in a frequentist or bayesian world as long as I have more modeling flexibility. I would also be interested in doing that in WINBUGS/JAGS.

-
Hard to advise - maybe you should post a link or specify in the detail what models you would like to use. You can do anything in WINBUGS/JAGS because you write the model yourself, so if you know exactly what you want you can do it. – Tomas Jan 2 '12 at 9:23
Also, if you are looking for modelling flexibility, then definitely go for WINBUGS/JAGS. In R, you can only do what they prepared for you, but in bayesian you are absolutely free to do anything (for the price of learning time, and you need to understand the models very well). – Tomas Jan 2 '12 at 9:28
I see you also asked this question at r-sig-mixed-models@r-project.org ... it's best not to cross-post, or at least to state explicitly that you're cross-posting. (I think r-sig-mixed-models might turn out to be more fruitful.) – Ben Bolker Jan 2 '12 at 14:03
I have several data sets and I would like to experiment with different covariances structures. I don't have a single, specific model I would like to fit but instead I would like to try most of the basic ones, such as the ones available in SAS support.sas.com/rnd/app/papers/glimmix.pdf – Antonio Pedro Ramos Jan 2 '12 at 20:04
By the way, this may be better for the statistics Stack Exchange site, as this is more about finding useful packages for this particular statistical purpose than about creating new code in R. As such, there may be a much more relevant audience on that website. – Iterator Jan 2 '12 at 22:24

## migrated from stackoverflow.comJan 2 '12 at 23:03

Longitudinal and mixed models in BUGS is talked about in Ch. 10 of Bayesian Ideas and Data Analysis. Below is a link to the book website which has some example code.

http://www.ics.uci.edu/~wjohnson/BIDA/BIDABook.html

-

I'm not sure what you mean by R not having "factor analytic models for covariance matrices" - can you clarify what you'd like to reproduce from SAS? To my knowledge this is feasible with a lot of different packages in R.

Regarding antedependence models, there is a book on this very topic that has associated R code and examples, at the first author's website.

I'm not sure if WinBUGS will bring you any luck, but I'd start with the aforementioned textbook - it seems to be authoritative on antedependence models. :)

-
Presumably the OP wants the covariance structures here: support.sas.com/documentation/cdl/en/statug/63033/HTML/default/… ... these can in principle be constructed via the corClasses facility in nlme, but it's not trivial and as far as I know hasn't been done ... – Ben Bolker Jan 2 '12 at 18:42
I mean that SAS has much more options for covariance structures than nlme in R, and they are all mature; compare: support.sas.com/rnd/app/papers/glimmix.pdf with stat.ethz.ch/R-manual/R-devel/library/nlme/html/corClasses.html – Antonio Pedro Ramos Jan 2 '12 at 19:56
I am also familiar with the mentioned book but to me it reads more like a theory book with some R code but without a mature R package. – Antonio Pedro Ramos Jan 2 '12 at 20:01
No offense, but it is imprecise to say "options for covariance structures" - I assume you mean to say that SAS has more options for specifying the covariance structures in estimating the parameters of certain types of parametric models, correct? But we're not making much progress here: what is it that you want to achieve? I've skimmed the GLMMIX documentation (which is rather shabby from a statistical perspective - a lot of gloss, not much math). What would you really like to do? (continued) – Iterator Jan 2 '12 at 22:30

I believe, with a slight learning curve, you could use one of the SEM packages in R: lavaan, OpenMX, or sem. I am just learning about SEM and these packages, but it does look to me that lavaan has a formula syntax that's much like other modeling (lm, lmer) in R, and SEM lets you do a lot of things with your covariance structure.

-