Re: [R] within-subject factors in lme
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 __ R-help@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.
Re: [R] within-subject factors in lme
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, [EMAIL PROTECTED] [EMAIL PROTECTED] 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 __ R-help@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.
Re: [R] within-subject factors in lme
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 __ R-help@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.
Re: [R] Within-subject factors in lme
Thanks for your suggestion. I guess the model you are fitting here has only a single random effect term, namely subject. If the effect of A depends on S, one needs to include an additional random effects term for the S:A interaction. It is not quite clear what you are after, but the 'if' sounds as you would like to include interactions between your fixed and random effects? This is done in the following way: lme (y ~ A + B, random= ~ A | S ) or lme (y ~ A + B, random= ~ B | S ) or lme (y ~ A + B, random= ~ A + B | S ) with redard to discussions on degrees of freedom (and thus testing in mixed-effects models) you may also want to refer to: I hope this helps. Regards, Lorenz Gygax - Swiss Federal Veterinary Office Centre for proper housing of ruminants and pigs Agroscope Reckenholz-Tänikon Research Station ART __ R-help@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.
Re: [R] Within-subject factors in lme: complemented
The internet address to complement this is: http://wiki.r-project.org/rwiki/doku.php?id=guides:lmer-tests sorry for the double posting! -Original Message- From: Gygax Lorenz ART Sent: Tuesday, January 16, 2007 7:32 AM To: r-help@stat.math.ethz.ch Subject: RE: [R] Within-subject factors in lme Thanks for your suggestion. I guess the model you are fitting here has only a single random effect term, namely subject. If the effect of A depends on S, one needs to include an additional random effects term for the S:A interaction. It is not quite clear what you are after, but the 'if' sounds as you would like to include interactions between your fixed and random effects? This is done in the following way: lme (y ~ A + B, random= ~ A | S ) or lme (y ~ A + B, random= ~ B | S ) or lme (y ~ A + B, random= ~ A + B | S ) with redard to discussions on degrees of freedom (and thus testing in mixed-effects models) you may also want to refer to: I hope this helps. Regards, Lorenz Gygax - Swiss Federal Veterinary Office Centre for proper housing of ruminants and pigs Agroscope Reckenholz-Tänikon Research Station ART __ R-help@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.
Re: [R] Within-subject factors in lme
Dear Kim, as far as I understandyour problem correct the specification of the model in lme is: lme( fixed=y ~ A*B, random=~1|S) Thilo On Friday 12 January 2007 15:54, Kim Mouridsen wrote: Dear R-users I'm considering a repeated measures experiment where two within-subject factors A (2 levels) and B (3 levels) have been measured for each of 14 subjects, S. I wish to test the effect of factor A. I know that a variance component model with random effects S, S:A, S:B and S:A:B can be fitted using aov: aov( y ~ A*B + Error(S/(A*B)) ) If there is no significant interaction, the test for the effect of A is carried out in the S:A error strata. How can a test for the effect of A be performed using lme from the nlme package? ( lme( y ~ A*B, random=~1|S/(A*B)) is apparently not correct ) Thanks in advance for your advice. Kim. __ R-help@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. -- Thilo Kellermann Department of Psychiatry und Psychotherapy RWTH Aachen University Pauwelstr. 30 52074 Aachen Tel.: +49 (0)241 / 8089977 Fax.: +49 (0)241 / 8082401 E-Mail: [EMAIL PROTECTED] __ R-help@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.
Re: [R] Within-subject factors in lme
Dear Thilo Thanks for your suggestion. I guess the model you are fitting here has only a single random effect term, namely subject. If the effect of A depends on S, one needs to include an additional random effects term for the S:A interaction. With lme I can get output for the effect of A which is very similar to the aov output using lme( y ~ A + B, random=~ 1|S/A ) but here I have cheated by not including factor B in the 'random=' terms. But the output from anova( lme( y ~ A + B, random=~ 1|S/A ) ) is numDF denDF F-value p-value (Intercept) 154 388.4006 .0001 B254 154.0193 .0001 A113 4.4581 0.0547 where the last line appears equivalent to the aov output: Error: Subject:Treatment Df Sum Sq Mean Sq F value Pr(F) A 1 0.66074 0.66074 4.4581 0.05467 . Residuals 13 1.92676 0.14821 But I still need to account for the random S:B interaction. I can see a similar issue has been discussed earlier, see eg https://stat.ethz.ch/pipermail/r-help/2006-August/111018.html Here, lme( y ~ A*B, random=~1|S ) was also suggested (essentially), but this gives quite different results from aov and the lme example above. In this particular case I get numDF denDF F-value p-value (Intercept) 167 388.3976 .0001 B 267 104.8436 .0001 A 167 10.3707 0.002 I have seen instances of something like random=list(S=pdBlocked(list(pdIdent(~A-1)..., but I can't get this to work (and I have no idea what this does). Best regards, Kim. 2007/1/12, Thilo Kellermann [EMAIL PROTECTED]: Dear Kim, as far as I understandyour problem correct the specification of the model in lme is: lme( fixed=y ~ A*B, random=~1|S) Thilo On Friday 12 January 2007 15:54, Kim Mouridsen wrote: Dear R-users I'm considering a repeated measures experiment where two within-subject factors A (2 levels) and B (3 levels) have been measured for each of 14 subjects, S. I wish to test the effect of factor A. I know that a variance component model with random effects S, S:A, S:B and S:A:B can be fitted using aov: aov( y ~ A*B + Error(S/(A*B)) ) If there is no significant interaction, the test for the effect of A is carried out in the S:A error strata. How can a test for the effect of A be performed using lme from the nlme package? ( lme( y ~ A*B, random=~1|S/(A*B)) is apparently not correct ) Thanks in advance for your advice. Kim. __ R-help@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. -- Thilo Kellermann Department of Psychiatry und Psychotherapy RWTH Aachen University Pauwelstr. 30 52074 Aachen Tel.: +49 (0)241 / 8089977 Fax.: +49 (0)241 / 8082401 E-Mail: [EMAIL PROTECTED] __ R-help@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.