Mr. Giles Crane,
 
I am new to R (only a month in).  My response is as best as I understand the 
workings of R (so if I'm wrong more experienced people plese help me out).
 
AOV is not really appropriate for an unbalanced model.  This is where you can 
rely on the lm() function using these steps:
(I find it easiest to show you with a real data set)
student gender male female computer
1        1   male  7.0    9.5      6.0
2        2   male  7.5    7.0      4.0
3        3   male  6.0    7.0      2.5
4        4   male  4.0    8.0      3.0
5        5   male  7.5   10.0      3.5
.
.
n              etc...
 
1)      Create a vector of levels for the measurement  points (1 for each 
measurement point):
 
meals <- c(1, 2, 3)
 
Where meals is the new vector name (a factor), and the numbers represent each 
measurement point.
 
2)      Create a within groups measurement point factor to house the levels you 
just created (this will be used later in our data frame(matrix style)) and in 
our Anova anaylsis):
 
meal.factor<- as.factor(meals)
 
Where meal.factor is the new factor with n levels to house our levels that 
describe our n numeric columns(measurement points).
 
3)      Create a matrix style data frame from the factor and levels that will 
be used to describe our numeric columns(measurement points):
 
meal.frame <- data.frame(meal.factor)
 
4)      Now create a bound vector containing the n numeric columns for later 
use in the linear model:
 
meal.bind<-cbind(breakfast , lunch, dinner)
 
5)      Create a linear model with the bound vector you just created.
 
meal.model<-lm(meal.bind~1)
 
6)      Use the Anova function from the car package to analyze our data (notice 
we are using the measurement point matrix style data frame and corresponding 
within groups factors as well as the linear model we just created):

 
analysis3 <- Anova(meal.model, idata = meal.frame, idesign = ~meal.factor) 
 
Note: we could have added the argument ,type=”III” but the default of Anova is 
to switch from type II to type III SS when there is only one intercept
 
7)      Now create a summary of the anova tables and information:
       summary(analysis)    Look below at the summary:
 
NOTE: Aova (from car) will give you type II SS and you can also specify type 
III SS using the ,type=”III” argument at the end of step 6.  The function anove 
on step 6 gives you type I SS.  Research each one of these SS and detemrine 
what works best for you.   

 
 
 
 
> From: pda...@gmail.com
> Date: Mon, 14 Mar 2011 20:58:17 +0100
> To: gilescr...@verizon.net
> CC: r-help@r-project.org
> Subject: Re: [R] AOV() may misslabel random effects.
> 
> 
> On Mar 14, 2011, at 17:57 , Giles Crane wrote:
> 
> > Greetings,
> > 
> > The aov() function may mislabel
> > the random effects as in the example below:
> > Has anybody else noticed this?
> 
> What's "mislabeled" about it??? Looks like you nave an unbalanced design (in 
> which case, aov() may be the wrong tool.)
> 
> -pd
> 
> > 
> > Cordially,
> > Giles Crane, MPH, ASA, NJPHA
> > gilescr...@verizon.net
> > 
> > > m2
> > 
> > Call:
> > aov(formula = y ~ ap + pe + Error(ju), data = d)
> > 
> > Grand Mean: 77.50667
> > 
> > Stratum 1: ju
> > 
> > Terms:
> > ap
> > Sum of Squares 4322.538
> > Deg. of Freedom 12
> > 
> > 13 out of 25 effects not estimable
> > Estimated effects may be unbalanced
> > 
> > Stratum 2: Within
> > 
> > Terms:
> > ap pe Residuals
> > Sum of Squares 7047.885 255.034 2981.290
> > Deg. of Freedom 25 2 35
> > 
> > Residual standard error: 9.229285
> > Estimated effects may be unbalanced
> > 
> > ______________________________________________
> > 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.
> 
> -- 
> Peter Dalgaard
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd....@cbs.dk Priv: pda...@gmail.com
> 
> ______________________________________________
> 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]]

______________________________________________
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.

Reply via email to