I don't think, this has been answered:> I'm trying to run a 3-way within-subject anova in lme with 3 > fixed factors (Trust, Sex, and Freq), but get stuck with handling > the random effects. As I want to include all the possible random > effects in the model, it would be something more or less > equivalent to using aov > > > fit.aov <- aov(Beta ~ > Trust*Sex*Freq+Error(Subj/(Trust*Sex*Freq)), > Model) > > However I'm not so sure what I should do in lme. Sure > > > lme(Beta ~ Trust*Sex*Freq, random = ~1|Subj, Model) > > works fine, but it only models the random effect of the > intercept. I tried the following 4 possibilities:If I understand correctly, you want to include the interactions between the random and fixed terms? This is done like: model.lme <- lme(Beta ~ Trust*Sex*Freq, random = ~Trust*Sex*Freq|Subj, Model) But this needs a lot of observations as quite a few parameters need to be estimated! Possibly, you can not include the variable Sex in this, because I assume that Subj is nested within Sex. If you just refer to within and between subject effects and their corresponding degrees of freedom: you should see this being handled automatically and correctly by lme e.g. in the output of anova (model.lme) Lorenz - Lorenz Gygax Centre for proper housing of ruminants and pigs Agroscope Reckenholz-T?nikon Research Station ART T?nikon, CH-8356 Ettenhausen / Switzerland
Hi Lorenz, I really appreciate your comments.> If I understand correctly, you want to include the interactions > between the random and fixed terms?Yes that is exactly I wanted to model.> This is done like: > > model.lme <- lme(Beta ~ Trust*Sex*Freq, > random = ~Trust*Sex*Freq|Subj, Model) > > But this needs a lot of observations as quite a few parameters need > to be estimated!Well, I tried this as well, but it seems R kept hanging there and never finished the modeling. It is very likely due to some singularity as you suspected about the large number of parameters needed to estimate. But this is not a problem with aov. So does it mean that I can't run a similar model to that in aov with lme? Sure I can simply run the following model fit.lme <- lme(Beta ~ Trust*Sex*Freq, random = ~1|Subj, Model) but I feel this is not good enough to account for cross-subject variations for those interactions. Why wouldn't those patterned variance-covariance matrix specifications work as I mentioned in my previous mail? Any more thoughts and suggestions?> Possibly, you can not include the variable Sex in this, because I > assume that Subj is nested within Sex.No, Sex is NOT a subject classifying factor. Instead it is a task- related within-subject factor. Again thanks a lot for your help, Gang On Aug 22, 2007, at 6:52 AM, <lorenz.gygax at art.admin.ch> <lorenz.gygax at art.admin.ch> wrote:> I don't think, this has been answered: > >> I'm trying to run a 3-way within-subject anova in lme with 3 >> fixed factors (Trust, Sex, and Freq), but get stuck with handling >> the random effects. As I want to include all the possible random >> effects in the model, it would be something more or less >> equivalent to using aov >> >>> fit.aov <- aov(Beta ~ >> Trust*Sex*Freq+Error(Subj/(Trust*Sex*Freq)), >> Model) >> >> However I'm not so sure what I should do in lme. Sure >> >>> lme(Beta ~ Trust*Sex*Freq, random = ~1|Subj, Model) >> >> works fine, but it only models the random effect of the >> intercept. I tried the following 4 possibilities: > > If I understand correctly, you want to include the interactions > between the random and fixed terms? This is done like: > > model.lme <- lme(Beta ~ Trust*Sex*Freq, > random = ~Trust*Sex*Freq|Subj, Model) > > But this needs a lot of observations as quite a few parameters need > to be estimated! Possibly, you can not include the variable Sex in > this, because I assume that Subj is nested within Sex. If you just > refer to within and between subject effects and their corresponding > degrees of freedom: you should see this being handled automatically > and correctly by lme e.g. in the output of anova (model.lme) > > Lorenz > - > Lorenz Gygax > Centre for proper housing of ruminants and pigs > Agroscope Reckenholz-T?nikon Research Station ART > T?nikon, CH-8356 Ettenhausen / Switzerland
> > If I understand correctly, you want to include the interactions > > between the random and fixed terms? > > Yes that is exactly I wanted to model. > > > This is done like: > > > > model.lme <- lme(Beta ~ Trust*Sex*Freq, > > random = ~Trust*Sex*Freq|Subj, Model) > > > > But this needs a lot of observations as quite a few > > parameters need to be estimated! > > Well, I tried this as well, but it seems R kept hanging there and > never finished the modeling. It is very likely due to some > singularity as you suspected about the large number of parameters > needed to estimate. But this is not a problem with aov. So does > it mean that I can't run a similar model to that in aov with lme?It depends what you mean by 'similar'. You could still include some of the interactions, e.g. by random = ~(Trust+Sex+Freq)^2|Subj, or even further reduced such as ~Trust+Sex+Freq|Subj. I am not very familiar with aov, but I would suspect that the model you calcualted in aov is not really the same than the one with all possible interactions in lme. In any case, I would personally trust lme much more than aov.> but I feel this is not good enough to account for cross-subject > variations for those interactions. Why wouldn't those patterned > variance-covariance matrix specifications work as I mentioned in > my previous mail? Any more thoughts and suggestions?Sorry, I have never really worked with those. Lorenz - Lorenz Gygax Centre for proper housing of ruminants and pigs Agroscope Reckenholz-T?nikon Research Station ART
I want to check whether all the components of a vector (or an array) are 0, and if they are I will skip the later computations. Of course I can create a loop to go through all the components. However is there an R function for this purpose more efficient than looping? Thanks a lot, Gang
an array is just a vector with attributes.> all ( diag(2) == 0 )[1] FALSE> all ( diag(2)*0 == 0 )[1] TRUE>On Tue, 28 Aug 2007, Gang Chen wrote:> I want to check whether all the components of a vector (or an array) > are 0, and if they are I will skip the later computations. Of course > I can create a loop to go through all the components. However is > there an R function for this purpose more efficient than looping? > > Thanks a lot, > Gang > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901