On Friday, September 11, 2015 at 8:18:39 AM UTC-5, Megan Smith wrote:
>
> For a statistical analysis in genomics, I need to evaluate a linear mixed 
> effects model hundreds of thousands of times.  I want to fit the model
>
> mod=fit(lmm(Y ~ X + (1|PatientID),Data))
>
> repeatedly in a loop with different outcome variables "Y" each time.  I 
> want to have the variable names for Y as arguments in the outside function, 
> and this would require me to evaluate Y within the formula to fit the 
> model.  Does anyone know how I can do this?  
>
> The problem I'm having is getting the Formula type to evaluate variables.  
> For example, I want to fit
> mod=fit(lmm(X10154 ~ X + (1|PatientID),Data))
> inside a function that has the string variable probeName="X10154" as an 
> argument of type UTF8String.  How can I call X10154 within the formula?
>
> The line mod=fit(lmm(X10154 ~ X + (1|PatientID),Data)) works.  
>
> However things like the following do not work and yield errors.
>
> mod=fit(lmm(probeName ~ X + (1|PatientID),Data))
>
> *ERROR: key not found: :probeName*
>
>
> mod=fit(lmm($probeName ~ X + (1|PatientID),Data))
>
>
It happens that a Formula has two fields, called lhs and rhs.  If you 
assign the formula to a name you can reassign the left hand side

In [3]:

ff = Y ~ 1 + X + (1|PatientID)

Out[3]:

Formula: Y ~ 1 + X + (1 | PatientID)

In [4]:

typeof(ff.lhs)

Out[4]:

Symbol

In [5]:

ff.lhs = Symbol("Z");

ff

Out[5]:

Formula: Z ~ 1 + X + (1 | PatientID)


If you are going to be fitting thousands of such models, I may be able to 
save you a lot of time.  I have been developing an alternative 
implementation of the linear mixed models in an unreleased package at

http://github.com/dmbates/ReTerms.jl

This package is merely a testing ground, I plan to refactor the code in 
MixedModels.jl to use these methods instead of the current approach, which 
is somewhat baroque.  Anyway, in the new approach it is rather 
straightforward to keep the same model representation and simply plug in a 
new response vector - I use this for simulations but it could be used for 
fitting many responses.

If you are interested in trying out ReTerms.jl please contact me off-list 
at [email protected] and I will send more detailed instructions.

Reply via email to