Message Boards Message Boards

0
|
20268 Views
|
11 Replies
|
7 Total Likes
View groups...
Share
Share this post:

How to estimate Variance Components in a mixed linear model ?

Posted 12 years ago
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
11 Replies
Posted 5 years ago

Wondering if M12.1 will have anything in it for these mixed linear models.

POSTED BY: Jason Zhao
Posted 4 years ago

How about mixed models in M12.2?

POSTED BY: Jim Baldwin
Wondering if M10 will have anything in it for these mixed linear models.
Posted 12 years 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
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 12 years 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
Posted 12 years 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
Posted 12 years ago
RLink seems to be very promissing!
POSTED BY: M Bohn
Posted 12 years 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
Posted 12 years 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
Start by reading up on  LinearModelFit,  then add questions about how to separate effects.
POSTED BY: Bruce Miller
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract