Would like to try my luck to see if I can catch your eyes. I was trying to do some contrasts within ANOVA. I searched the archive and found a clue posted by Steffen Katzner ( http://tolstoy.newcastle.edu.au/R/help/06/01/19385.html) I have three levels for a factor names "StdLot" and want to make three comparisons, 1 vs 2, 1 vs 3 and 2 vs 3. First, contrasts(d3$StdLot,3)<-matrix(c(1,-1, 0,0,1,-1,1,0,-1),3,3) #d3 is the data set. set up the contrast matrix Second, aov(Bkg~StdLot,na.rm=T,data=d3,contrasts=contrasts(d3$StdLot))->mod.aov #ANOVA, Finally, summary(mod.aov,split=list(StdLot=list('1 vs 2'=1,'2 vs 3'=2,'1 vs 3'=3))) #comparison summary Here is the final result I got, the third comparison is missing. Does anyone have any idea what is wrong here? If I change the order of the comparisons it's always the third one missing. So I guess it's not due to the data. Appreciate any comment. Df Sum Sq Mean Sq F value Pr(>F) StdLot 2 1.905 0.953 10.3769 3.710e-05 *** StdLot: 1 vs 2 1 0.223 0.223 2.4239 0.1200 StdLot: 2 vs 3 1 1.683 1.683 18.3299 2.162e-05 *** StdLot: 1 vs 3 1 Residuals 601 55.173 0.092 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 2 observations deleted due to missingness -- Jun Shen PhD PK/PD Scientist BioPharma Services Millipore Corporation 15 Research Park Dr. St Charles, MO 63304 Direct: 636-720-1589 [[alternative HTML version deleted]]
Hi Jun,>> I have three levels for a factor names "StdLot" and want to make three >> comparisons, 1 vs 2, 1 vs 3 and 2 vs 3.With only three levels to your factor, the contrast matrix you are specifying is over-parametrized (i.e. over-specified): it has 3 rows and 3 columns. ## Look at the default behaviour contrasts(d3$StdLot) <- NULL contrasts(d3$StdLot) contrasts(d3$StdLot) <- contr.helmert contrasts(d3$StdLot) I think what you really want are linear contrasts, which you will find in package car (?linear.hypothesis), in gmodels (?estimable) [based on Frank Harrell's approach; so look at his package Design], and package multcomp, amongst others. Regards, Mark. Jun Shen-3 wrote:> > Would like to try my luck to see if I can catch your eyes. > > I was trying to do some contrasts within ANOVA. I searched the archive and > found a clue posted by Steffen Katzner > ( http://tolstoy.newcastle.edu.au/R/help/06/01/19385.html) > > I have three levels for a factor names "StdLot" and want to make three > comparisons, 1 vs 2, 1 vs 3 and 2 vs 3. > > First, > contrasts(d3$StdLot,3)<-matrix(c(1,-1, 0,0,1,-1,1,0,-1),3,3) #d3 is the > data set. set up the contrast matrix > > Second, > aov(Bkg~StdLot,na.rm=T,data=d3,contrasts=contrasts(d3$StdLot))->mod.aov > #ANOVA, > > Finally, > summary(mod.aov,split=list(StdLot=list('1 vs 2'=1,'2 vs 3'=2,'1 vs 3'=3))) > #comparison summary > > Here is the final result I got, the third comparison is missing. Does > anyone > have any idea what is wrong here? If I change the order of the comparisons > it's always the third one missing. So I guess it's not due to the data. > Appreciate any comment. > > Df Sum Sq Mean Sq F value Pr(>F) > StdLot 2 1.905 0.953 10.3769 3.710e-05 *** > StdLot: 1 vs 2 1 0.223 0.223 2.4239 0.1200 > StdLot: 2 vs 3 1 1.683 1.683 18.3299 2.162e-05 *** > StdLot: 1 vs 3 1 > Residuals 601 55.173 0.092 > --- > Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 > 2 observations deleted due to missingness > > > -- > Jun Shen PhD > PK/PD Scientist > BioPharma Services > Millipore Corporation > 15 Research Park Dr. > St Charles, MO 63304 > Direct: 636-720-1589 > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org 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. > >-- View this message in context: http://www.nabble.com/Contrasts-within-ANOVA-frame-%28Repost%29-tp25052361p25057955.html Sent from the R help mailing list archive at Nabble.com.
Dr Shen Even though you pose 3 contrasts, there are only 2 degrees of freedom as the 3rd contrast is the sum of the first two. Your aov output states this as StdLot has only 2 df. Having used up your df, the aov has nothing to report. Joe Joseph F. Lucke Senior Statistician Research Institute on Addictions State University of New York at Buffalo 1021 Main Street Buffalo, NY 14203-1016 Office: 716-887-6807 Fax: 716-887-2510 http://www.ria.buffalo.edu/profiles/lucke.html Jun Shen <jun.shen.ut@gmail.com> Sent by: r-help-bounces@r-project.org 08/19/2009 05:33 PM To r-help@r-project.org cc Subject [R] Contrasts within ANOVA frame (Repost) Would like to try my luck to see if I can catch your eyes. I was trying to do some contrasts within ANOVA. I searched the archive and found a clue posted by Steffen Katzner ( http://tolstoy.newcastle.edu.au/R/help/06/01/19385.html) I have three levels for a factor names "StdLot" and want to make three comparisons, 1 vs 2, 1 vs 3 and 2 vs 3. First, contrasts(d3$StdLot,3)<-matrix(c(1,-1, 0,0,1,-1,1,0,-1),3,3) #d3 is the data set. set up the contrast matrix Second, aov(Bkg~StdLot,na.rm=T,data=d3,contrasts=contrasts(d3$StdLot))->mod.aov #ANOVA, Finally, summary(mod.aov,split=list(StdLot=list('1 vs 2'=1,'2 vs 3'=2,'1 vs 3'=3))) #comparison summary Here is the final result I got, the third comparison is missing. Does anyone have any idea what is wrong here? If I change the order of the comparisons it's always the third one missing. So I guess it's not due to the data. Appreciate any comment. Df Sum Sq Mean Sq F value Pr(>F) StdLot 2 1.905 0.953 10.3769 3.710e-05 *** StdLot: 1 vs 2 1 0.223 0.223 2.4239 0.1200 StdLot: 2 vs 3 1 1.683 1.683 18.3299 2.162e-05 *** StdLot: 1 vs 3 1 Residuals 601 55.173 0.092 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 2 observations deleted due to missingness -- Jun Shen PhD PK/PD Scientist BioPharma Services Millipore Corporation 15 Research Park Dr. St Charles, MO 63304 Direct: 636-720-1589 [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org 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. [[alternative HTML version deleted]]