angelo.arcadi at virgilio.it
2015-Nov-26 03:04 UTC
[R] R: RE: Syntax error in using Anova (car package)
Dear Prof. John Fox, thanks a lot for your answer. Do you mean that my data set should have 19 rows (one for each of the 19 subjects) and 144 columns (that is 72 trials * 2 dependent variables)? So should the dataframe look like this? Subject Stimulus_1.Centroid.repetition1 Stimulus_1.Centroid.repetition2 Stimulus_1.Peak.repetition1 Stimulus_1.Peak.repetition2 Subject1 1000 2000 10 20 Subject2 500 600 5 6 ...... SubjectN However, differently from the example reported in the document you kindly provided, my experiment has two dependent variables. My guess is that the analysis should be the following (considering 12 types of stimuli and 6 repetitions for each of them, and 2 dependent variables) stimulus_type <- factor(rep(c("Stimulus_1", "Stimulus_2", "Stimulus_3", "Stimulus_4", "Stimulus_5", "Stimulus_6", "Stimulus_7", "Stimulus_8", "Stimulus_9", "Stimulus_10", "Stimulus_11", "Stimulus_12"), c(6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6)), levels=c("Stimulus_1", "Stimulus_2", "Stimulus_3", "Stimulus_4", "Stimulus_5", "Stimulus_6", "Stimulus_7", "Stimulus_8", "Stimulus_9", "Stimulus_10", "Stimulus_11", "Stimulus_12")) repetitions <- ordered(rep(1:6, 12)) idata <- data.frame(stimulus_type, repetitions) Notably, now idata has 72 rows (should it have 144 rows instead?). Then I continue with: mod.ok <- lm(cbind(Stimulus_1.Centroid.repetition1, ....., Stimulus_12.Peak. repetition2) ~ Subject, data=scrd) av.ok <- Anova(mod.ok, idata=idata, idesign=~stimulus_type*repetitions) Am I correct? Thanks in advance Best regards Angelo>----Messaggio originale---- >Da: jfox at mcmaster.ca >Data: 25-nov-2015 17.23 >A: "angelo.arcadi at virgilio.it"<angelo.arcadi at virgilio.it> >Cc: "r-help at r-project.org"<r-help at r-project.org> >Ogg: RE: Syntax error in using Anova (car package) > >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 >> >> >> >> > >
At this point, it seem obvious to me that you would benefit by local statistical consulting, rather than further badgering on this list, as you seem confused by both the underlying statistical concepts and how they need to be handled in R/car. Pursuing your current course seems destined to lead to folly. Of course, both you and John (and others) are free to disagree ... Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Wed, Nov 25, 2015 at 7:04 PM, angelo.arcadi at virgilio.it <angelo.arcadi at virgilio.it> wrote:> > > Dear Prof. John Fox, > thanks a lot for your answer. Do you mean that my data set should have 19 rows > (one for each of the 19 subjects) > and 144 columns (that is 72 trials * 2 dependent variables)? So should the > dataframe look like this? > > Subject Stimulus_1.Centroid.repetition1 Stimulus_1.Centroid.repetition2 > Stimulus_1.Peak.repetition1 Stimulus_1.Peak.repetition2 > Subject1 1000 2000 > 10 20 > Subject2 500 > 600 5 6 > ...... > SubjectN > > > However, differently from the example reported in the document you kindly > provided, my experiment > has two dependent variables. > My guess is that the analysis should be the following (considering 12 types of > stimuli and 6 repetitions > for each of them, and 2 dependent variables) > > > > stimulus_type <- factor(rep(c("Stimulus_1", "Stimulus_2", "Stimulus_3", > "Stimulus_4", "Stimulus_5", "Stimulus_6", > "Stimulus_7", "Stimulus_8", "Stimulus_9", "Stimulus_10", "Stimulus_11", > "Stimulus_12"), c(6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6)), > levels=c("Stimulus_1", "Stimulus_2", "Stimulus_3", "Stimulus_4", "Stimulus_5", > "Stimulus_6", > "Stimulus_7", "Stimulus_8", "Stimulus_9", "Stimulus_10", "Stimulus_11", > "Stimulus_12")) > > repetitions <- ordered(rep(1:6, 12)) > > idata <- data.frame(stimulus_type, repetitions) > > Notably, now idata has 72 rows (should it have 144 rows instead?). Then I > continue with: > > > mod.ok <- lm(cbind(Stimulus_1.Centroid.repetition1, ....., Stimulus_12.Peak. > repetition2) ~ Subject, data=scrd) > > av.ok <- Anova(mod.ok, idata=idata, idesign=~stimulus_type*repetitions) > > > Am I correct? > > Thanks in advance > > Best regards > > Angelo > > > > >>----Messaggio originale---- >>Da: jfox at mcmaster.ca >>Data: 25-nov-2015 17.23 >>A: "angelo.arcadi at virgilio.it"<angelo.arcadi at virgilio.it> >>Cc: "r-help at r-project.org"<r-help at r-project.org> >>Ogg: RE: Syntax error in using Anova (car package) >> >>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 >>> >>> >>> >>> >> >> > > ______________________________________________ > 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.
Dear Angelo, I'll answer the question that you posed but also try to explain why the analysis that you want to perform probably doesn't make sense. Yes, if you want to take the MANOVA approach to repeated measures, you have 144 "dependent variables." The purpose if the idata and idesign arguments are to define the structure of the repeated measures and of the model to be fit to them. In your case, idata would have 144 rows and 3 columns for the combinations of levels of stimulus, repetition, and dependent variable. You can't, however, perform a MANOVA because with only 19 subjects the SSP matrices will be singular. Although you could perform a univariate repeated-measures ANOVA (if the two dependent variables are on the same scale), that's likely inadvisable. With only 19 subjects, the within-subjects design is probably too complex. Is it possible to simplify? Is anything lost by averaging over repetitions, for example, or are you interested in how the responses develop over repetitions? If the latter, maybe you don't have enough data. Is there a compelling reason not to do separate analyses for the two dependent variables, particularly if they're on different scales? Burt Gunter suggested that you'd do well to get some help, and I think that's good advice. You're representing this as a software-syntax problem but I think that there are serious issues about how best to perform the statistical analysis. There's a limit to how far you can get in an email discussion. Best, John> -----Original Message----- > From: angelo.arcadi at virgilio.it [mailto:angelo.arcadi at virgilio.it] > Sent: November 25, 2015 10:04 PM > To: Fox, John <jfox at mcmaster.ca> > Cc: r-help at r-project.org > Subject: R: RE: Syntax error in using Anova (car package) > > > > Dear Prof. John Fox, > thanks a lot for your answer. Do you mean that my data set should have 19 > rows (one for each of the 19 subjects) and 144 columns (that is 72 trials * 2 > dependent variables)? So should the dataframe look like this? > > Subject Stimulus_1.Centroid.repetition1 Stimulus_1.Centroid.repetition2 > Stimulus_1.Peak.repetition1 Stimulus_1.Peak.repetition2 > Subject1 1000 2000 > 10 20 > Subject2 500 > 600 5 6 > ...... > SubjectN > > > However, differently from the example reported in the document you kindly > provided, my experiment has two dependent variables. > My guess is that the analysis should be the following (considering 12 types of > stimuli and 6 repetitions for each of them, and 2 dependent variables) > > > > stimulus_type <- factor(rep(c("Stimulus_1", "Stimulus_2", "Stimulus_3", > "Stimulus_4", "Stimulus_5", "Stimulus_6", "Stimulus_7", "Stimulus_8", > "Stimulus_9", "Stimulus_10", "Stimulus_11", "Stimulus_12"), c(6, 6, 6, 6, 6, 6, 6, > 6, 6, 6, 6, 6)), levels=c("Stimulus_1", "Stimulus_2", "Stimulus_3", "Stimulus_4", > "Stimulus_5", "Stimulus_6", "Stimulus_7", "Stimulus_8", "Stimulus_9", > "Stimulus_10", "Stimulus_11", > "Stimulus_12")) > > repetitions <- ordered(rep(1:6, 12)) > > idata <- data.frame(stimulus_type, repetitions) > > Notably, now idata has 72 rows (should it have 144 rows instead?). Then I > continue with: > > > mod.ok <- lm(cbind(Stimulus_1.Centroid.repetition1, ....., Stimulus_12.Peak. > repetition2) ~ Subject, data=scrd) > > av.ok <- Anova(mod.ok, idata=idata, idesign=~stimulus_type*repetitions) > > > Am I correct? > > Thanks in advance > > Best regards > > Angelo > > > > > >----Messaggio originale---- > >Da: jfox at mcmaster.ca > >Data: 25-nov-2015 17.23 > >A: "angelo.arcadi at virgilio.it"<angelo.arcadi at virgilio.it> > >Cc: "r-help at r-project.org"<r-help at r-project.org> > >Ogg: RE: Syntax error in using Anova (car package) > > > >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 > >> > >> > >> > >> > > > > >