Group Abstract Group Abstract

Message Boards Message Boards

How to estimate Variance Components in a mixed linear model ?

GROUPS:
Hello,
How do I fit a mixed linear model to my data using Mathematica? The model contains random and fixed effects. In addition, I am interested in estimating variance components for each random effect used in my model! 

Any hints that steer me into the right direct are appreciated!

Martin
POSTED BY: M Bohn
Answer
11 months ago
Start by reading up on  LinearModelFit,  then add questions about how to separate effects.
POSTED BY: Bruce Miller
Answer
11 months ago
I don't think that Mathematica has built in functionality for mixed linear models. You may have to program this yourself. Alternatively, you could use R to do so. If you want to do it via Mathematica, you have RLink that may come in useful. 
POSTED BY: Asim Ansari
Answer
11 months ago
Bruce and Asim, many thanks for your advice and suggestions!
I hope that in the future the Mathematica staff addresses this gap!
POSTED BY: M Bohn
Answer
11 months ago
RLink seems to be very promissing!
POSTED BY: M Bohn
Answer
11 months ago
I started to work with RLink and this is actually the way to go! So far it works flawlessly running mixed linear models and estimating variance components using R package "lme4" within Mathematica.
POSTED BY: M Bohn
Answer
10 months ago
Hi Martin

It would be great for the community if you can post the details of a small working example, i.e, some simple data and code. 

Asim
POSTED BY: Asim Ansari
Answer
10 months ago
Blog Post: Jon McLoone, Why Would a Mathematica User Care about R?
http://blog.wolfram.com/2013/05/22/why-would-a-mathematica-user-care-about-r/

CRAN package repository
http://cran.cnr.berkeley.edu/web/packages/
POSTED BY: Christopher French
Answer
10 months ago
As Asim suggested, I used R via RLink to estimate variance componets.
  • The sample data set "Example_DataSet1.csv" is availalbe here: https://dl.dropboxusercontent.com/u/15488405/Example_DataSet1.csv. All factors in the model are regarded as random effects.
  • I used the following code:
 Needs["RLink`"]
 InstallR[ ]
 
 REvaluate["
   {
   FAC1=as.factor(example$Fac1)
   FAC2=as.factor(example$Fac2)
   FAC3=as.factor(example$Fac3)
   FAC4=as.factor(example$Fac4)
  VAR1=as.numeric(example$Var1)
  }
  "];
REvaluate["hist(VAR1)"]

StringJoin@Riffle[#, "\n"] &@
REvaluate["
  {
  library(lme4)
  fit2 = lmer(formula= VAR1 ~ (1|FAC1) + (1|FAC2%in%FAC1) + (1|FAC4) + (1|FAC1:FAC4))
  summary.text = capture.output(print( summary(fit2)))
  }
  "]
POSTED BY: M Bohn
Answer
10 months ago
Wondering if M10 will have anything in it for these mixed linear models.
POSTED BY: Christopher French
Answer
4 months ago