[R-sig-ME] lmer and lme: using apply etc.

BXC (Bendix Carstensen) bxc at steno.dk
Mon Sep 10 12:40:51 CEST 2007


Isn't it because you use

data2[2]/ data2[25]

instead of

data2[,2]/ data2[,25] 

Best 
Bendix
______________________________________________

Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2-4
DK-2820 Gentofte
Denmark
+45 44 43 87 38 (direct)
+45 30 75 87 38 (mobile)
+45 44 43 73 13 (fax)
bxc at steno.dk   http://www.biostat.ku.dk/~bxc 

> -----Original Message-----
> From: r-sig-mixed-models-bounces at r-project.org 
> [mailto:r-sig-mixed-models-bounces at r-project.org] On Behalf Of AJ Smit
> Sent: Monday, September 10, 2007 6:39 AM
> To: r-sig-mixed-models at r-project.org
> Subject: [R-sig-ME] lmer and lme: using apply etc.
> 
> Dear Mixed Model users,
> 
> I want to fit the same mixed model to each of 21 variables 
> (columns) in my dataset. If coded individually for each 
> variable it would look like this:
> 
> lmer(colour ~ feed + (-1 + feed | taster), data = data2)
> 
> Then I just change 'colour' and run through the variables on 
> at a time. Or I can use apply or for statements like this to 
> cycle through each variable like this:
> 
> auto <- function(x) lmer(x ~ data2$feed + (-1 + data2$feed | data2
> $taster))
> apply(data2[3:22], 2, auto)
> 
> or
> 
> for(i in 3:22) print(c(names(data2[i]), 
> summary(lmer(data2[,i] ~ 1 + data2$feed + (-1 + data2$feed | 
> data2$taster)))))
> 
> Either works fine. However, when I try the same with lme it does not
> work:
> 
>  > for(i in 3:22) lme(data2[,i] ~ data2[25], random = ~1 | 
> data2[2]/ data2[25], method = "ML")
> 
> Error in model.frame(formula, rownames, variables, varnames, 
> extras, extranames,  :
> 	invalid type (list) for variable 'data2'
> 
> (column 25 is has the name taster, and 2 feed)
> 
> Any ideas why it works for one but not the other? I suppose I 
> could stack the 21 response variable and then use dummy 
> variables to code the multivariate response, but that would 
> be a bit cumbersome.
> 
> Thanks,
> AJ
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Dr Albertus J Smit
> (Marine Biologist)
> School of Biological & Conservation Sciences G. Campbell 
> Building University of KwaZulu-Natal Howard College Campus 
> Durban 4041, South Africa
> 
> E-mail: smitaj at ukzn.ac.za
> Tel. +27 031 260 7410;
> Fax +27 031 260 2029
> 
> Marine Biology web page: http://marinesci.ukzn.ac.za/biology
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> "The ocean weeds out, from all the races of mankind that come 
> upon it to make a living, a certain type of person. This type 
> of person stays with the ocean, and the rest are cast back 
> ashore to deal with the land people." ~~ Wilbert Chapman
> 
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list 
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>




More information about the R-sig-mixed-models mailing list