angelo.arcadi at virgilio.it
2015-Nov-25 16:30 UTC
[R] Syntax error in using Anova (car package)
Dear list members, I am getting an error while performing a repeated measures MANOVA using the Anova function of the "car" package. I want to apply it on the results of an experiment involving 19 participants, who were subjected to 36 stimuli, each stimulus was repeated twice for a total of 72 trials per subject. Participants had to adjust two parameters of sounds, Centroid and Sound_Level_Peak, for each stimulus. This is the head of my dataset (dependent variables: Centroid and Sound_Level_Peak; independent variables: Mat (6 levels) and Sh (2 levels)).> head(scrd)Subject Mat Sh Centroid Sound_Level_Peak 1 Subject1 C DS 1960.2 -20.963 2 Subject1 C SN 5317.2 -42.741 3 Subject1 G DS 11256.0 -16.480 4 Subject1 G SN 9560.3 -19.682 5 Subject1 M DS 4414.1 -33.723 6 Subject1 M SN 4946.1 -23.648 Based on my understanding of the online material I found, this is the procedure I used: idata <- data.frame(scrd$Subject) mod.ok <- lm(cbind(Centroid,Sound_Level_Peak) ~ Mat*Sh,data=scrd) av.ok <- Anova(mod.ok, idata=idata, idesign=~scrd$Subject) I get the following error Error in check.imatrix(X.design) : Terms in the intra-subject model matrix are not orthogonal. Can anyone please tell me what is wrong in my formulas? Thanks in advance Best regards Angelo [[alternative HTML version deleted]]
Dear Angelo, I'm afraid that this is badly confused. To use Anova() for repeated measures, the data must be in "wide" format, with one row per subject. To see how this works, check out the OBrienKaiser example in ?Anova and ?OBrienKaiser, or for more detail, the R Journal paper at <{http://journal.r-project.org/archive/2013-1/RJournal_2013-1_fox-friendly-weisberg.pdf>. I hope this helps, John ----------------------------------------------- John Fox, Professor McMaster University Hamilton, Ontario, Canada http://socserv.socsci.mcmaster.ca/jfox/> -----Original Message----- > From: angelo.arcadi at virgilio.it [mailto:angelo.arcadi at virgilio.it] > Sent: Wednesday, November 25, 2015 11:30 AM > To: r-help at r-project.org > Cc: Fox, John > Subject: Syntax error in using Anova (car package) > > Dear list members, > I am getting an error while performing a repeated measures MANOVA using > the Anova function > of the "car" package. I want to apply it on the results of an experiment > involving 19 participants, > who were subjected to 36 stimuli, each stimulus was repeated twice for a > total of 72 trials > per subject. Participants had to adjust two parameters of sounds, > Centroid and Sound_Level_Peak, > for each stimulus. This is the head of my dataset (dependent variables: > Centroid and > Sound_Level_Peak; independent variables: Mat (6 levels) and Sh (2 > levels)). > > > head(scrd) > Subject Mat Sh Centroid Sound_Level_Peak > 1 Subject1 C DS 1960.2 -20.963 > 2 Subject1 C SN 5317.2 -42.741 > 3 Subject1 G DS 11256.0 -16.480 > 4 Subject1 G SN 9560.3 -19.682 > 5 Subject1 M DS 4414.1 -33.723 > 6 Subject1 M SN 4946.1 -23.648 > > > Based on my understanding of the online material I found, this is the > procedure I used: > > idata <- data.frame(scrd$Subject) > mod.ok <- lm(cbind(Centroid,Sound_Level_Peak) ~ Mat*Sh,data=scrd) > av.ok <- Anova(mod.ok, idata=idata, idesign=~scrd$Subject) > > > I get the following error > > Error in check.imatrix(X.design) : > Terms in the intra-subject model matrix are not orthogonal. > > > Can anyone please tell me what is wrong in my formulas? > > Thanks in advance > > Best regards > > Angelo > > > >
> On Nov 25, 2015, at 8:30 AM, angelo.arcadi at virgilio.it wrote: > > Dear list members, > I am getting an error while performing a repeated measures MANOVA using the Anova function > of the "car" package. I want to apply it on the results of an experiment involving 19 participants, > who were subjected to 36 stimuli, each stimulus was repeated twice for a total of 72 trials > per subject. Participants had to adjust two parameters of sounds, Centroid and Sound_Level_Peak, > for each stimulus. This is the head of my dataset (dependent variables: Centroid and > Sound_Level_Peak; independent variables: Mat (6 levels) and Sh (2 levels)). > >> head(scrd) > Subject Mat Sh Centroid Sound_Level_Peak > 1 Subject1 C DS 1960.2 -20.963 > 2 Subject1 C SN 5317.2 -42.741 > 3 Subject1 G DS 11256.0 -16.480 > 4 Subject1 G SN 9560.3 -19.682 > 5 Subject1 M DS 4414.1 -33.723 > 6 Subject1 M SN 4946.1 -23.648 > > > Based on my understanding of the online material I found, this is the procedure I used: > > idata <- data.frame(scrd$Subject) > mod.ok <- lm(cbind(Centroid,Sound_Level_Peak) ~ Mat*Sh,data=scrd) > av.ok <- Anova(mod.ok, idata=idata, idesign=~scrd$Subject) > > > I get the following error > > Error in check.imatrix(X.design) : > Terms in the intra-subject model matrix are not orthogonal. > > > Can anyone please tell me what is wrong in my formulas?I suspect that instead of `idesign=~scrd$Subject` that you may want `idesign=~scrd|Subject` or after experimenting with an example in ?Anova, more probably `idesign=~scrd*Subject` The `$` operator is generally not correctly used in formulas, since it would violate the scoping expectations of the package authors. It would be pulling in a vector of length nrow(scrd) from the object outside the function evaluation frame. I also question whether the repeated measures within trial might also be needed to be accounted for in the ?idata' object and ?idesign' formula. I?m not a real statistician, so this is based more on syntactical reasoning rather than considered statistical advice. You probably do need to be consulting a real statistician.> > Thanks in advance > > Best regards > > Angelo > > [[alternative HTML version deleted]]This is a plain text mailing list, although your current posting seems to have survived intact.> > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.David Winsemius Alameda, CA, USA
> On Nov 25, 2015, at 9:23 AM, Fox, John <jfox at mcmaster.ca> wrote: > > Dear Angelo, > > I'm afraid that this is badly confused. To use Anova() for repeated measures, the data must be in "wide" format, with one row per subject. To see how this works, check out the OBrienKaiser example in ?Anova and ?OBrienKaiser, or for more detail, the R Journal paper at <{http://journal.r-project.org/archive/2013-1/RJournal_2013-1_fox-friendly-weisberg.pdf>.I got an error with that link, but this link succeeded: https://journal.r-project.org/archive/2013-1/fox-friendly-weisberg.pdf> > I hope this helps, > John > > ----------------------------------------------- > John Fox, Professor > McMaster University > Hamilton, Ontario, Canada > http://socserv.socsci.mcmaster.ca/jfox/ > > > >> -----Original Message----- >> From: angelo.arcadi at virgilio.it [mailto:angelo.arcadi at virgilio.it] >> Sent: Wednesday, November 25, 2015 11:30 AM >> To: r-help at r-project.org >> Cc: Fox, John >> Subject: Syntax error in using Anova (car package) >> >> Dear list members, >> I am getting an error while performing a repeated measures MANOVA using >> the Anova function >> of the "car" package. I want to apply it on the results of an experiment >> involving 19 participants, >> who were subjected to 36 stimuli, each stimulus was repeated twice for a >> total of 72 trials >> per subject. Participants had to adjust two parameters of sounds, >> Centroid and Sound_Level_Peak, >> for each stimulus. This is the head of my dataset (dependent variables: >> Centroid and >> Sound_Level_Peak; independent variables: Mat (6 levels) and Sh (2 >> levels)). >> >>> head(scrd) >> Subject Mat Sh Centroid Sound_Level_Peak >> 1 Subject1 C DS 1960.2 -20.963 >> 2 Subject1 C SN 5317.2 -42.741 >> 3 Subject1 G DS 11256.0 -16.480 >> 4 Subject1 G SN 9560.3 -19.682 >> 5 Subject1 M DS 4414.1 -33.723 >> 6 Subject1 M SN 4946.1 -23.648 >> >> >> Based on my understanding of the online material I found, this is the >> procedure I used: >> >> idata <- data.frame(scrd$Subject) >> mod.ok <- lm(cbind(Centroid,Sound_Level_Peak) ~ Mat*Sh,data=scrd) >> av.ok <- Anova(mod.ok, idata=idata, idesign=~scrd$Subject) >> >> >> I get the following error >> >> Error in check.imatrix(X.design) : >> Terms in the intra-subject model matrix are not orthogonal. >> >> >> Can anyone please tell me what is wrong in my formulas? >> >> Thanks in advance >> >> Best regards >> >> Angelo >> >> >> >> > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.David Winsemius Alameda, CA, USA