anova - aov() error term in R: what's the difference bw Error(id) and Error(id/timevar) specification? -


what difference between aov(depvar~timevar+error(id)) , aov(depvar~timevar+error(id/timevar)) formula specifications? these 2 variants produce different results.

the same question once asked here: https://stats.stackexchange.com/questions/60108/how-to-write-the-error-term-in-repeated-measures-anova-in-r however, i'd repeat more appropriate example.

here example created:

var=rep(na,180) id=rep(1:20,each=180/20) group=rep(rep(1:2,each=9),180/(9*2)) time1=rep(rep(1:3,each=3),180/(3*3)) time2=rep(c(8,15,20),180/3)  var[group==1&time1==1&time2==8]=runif(10,105,115) var[group==2&time1==1&time2==8]=runif(10,105,115) var[group==1&time1==1&time2==15]=runif(10,95,105) var[group==2&time1==1&time2==15]=runif(10,95,105) var[group==1&time1==1&time2==20]=runif(10,85,95) var[group==2&time1==1&time2==20]=runif(10,85,95)  var[group==1&time1==2&time2==8]=runif(10,95,105) var[group==2&time1==2&time2==8]=runif(10,95,105) var[group==1&time1==2&time2==15]=runif(10,85,95) var[group==2&time1==2&time2==15]=runif(10,75,85) var[group==1&time1==2&time2==20]=runif(10,75,85) var[group==2&time1==2&time2==20]=runif(10,65,75)  var[group==1&time1==3&time2==8]=runif(10,95,105) var[group==2&time1==3&time2==8]=runif(10,95,105) var[group==1&time1==3&time2==15]=runif(10,85,95) var[group==2&time1==3&time2==15]=runif(10,75,85) var[group==1&time1==3&time2==20]=runif(10,75,85) var[group==2&time1==3&time2==20]=runif(10,65,75)  df=data.frame(id,var,group,time1,time2) df$id=factor(df$id) df$group=factor(df$group) df$time1=factor(df$time1) df$time2=factor(df$time2) 

performing aov() on gets different results depending on error() term specification:

just 1 time term:

> summary(aov(var~time1+error(id),data=df)) error: id       df sum sq mean sq f value pr(>f)       residuals 19  958.4   50.44                error: within        df sum sq mean sq f value   pr(>f)            time1       2   7538    3769   30.41 6.72e-12 ***        residuals 158  19584     124           > summary(aov(var~time1+error(id/time1),data=df)) error: id       df sum sq mean sq f value pr(>f)       residuals 19  958.4   50.44                error: id:time1       df sum sq mean sq f value pr(>f)           time1      2   7538    3769   211.5 <2e-16 ***       residuals 38    677      18                          ---      signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 error: within        df sum sq mean sq f value pr(>f)        residuals 120  18907   157.6     

or both time terms (don't type output here sake of space, may check on own):

summary(aov(var~group*time1*time2+error(id/(group*time1*time2)),data=df))  summary(aov(var~group*time1*time2+error(id),data=df))  

why happen? variant correct?

here's blog post that'll break down each means under "random effects in classical anova" section.

from blog, here's summary "dividing" in error term means.

aov(y ~ error(a), data=d)               # lone random effect aov(y ~ b + error(a/b), data=d)         # random, b fixed, b nested within aov(y ~ (b*x) + error(a/(b*x)), data=d) # b , x interact within levels of 

so question,

aov(depvar~timevar+error(id/timevar)) 

means have random effect id fix timevar timevar nested within id levels versus

aov(depvar~timevar+error(id)) 

which taking id random effects no constraint on other variables.

source: http://conjugateprior.org/2013/01/formulae-in-r-anova/

this might prove useful well, code going on analysis of variance has recommendations on learning anova.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -