UW-Madison PSYCH 610 - Mixed Anova, One Factor Between, One Within

Unformatted text preview:

610 – R11 Prof Colleen F. MooreMixed Anova, One Factor Between, One WithinPsychology 610, University of WisconsinThis tutorial uses data from Winer’s (1971, 2nd edition) anova book, p. 806. The data areavailable on my website as ‘Winerp806.xls’.*** Warning: Use the ‘aov’ methods here for BALANCED designs only. See the end ofthis handout and Handout 610-R12 for methods for designs that are not balanced in thebetween-participants part of the design.Contents:I. Bring in data and arrangeII. Use ‘aov’ for analysis of variance, graph results; includes puttingseveral graphs on one page.III. Follow-up tests (paired comparisons on cell means, interactioncontrasts with pooled or partitioned error) (Balanced Designs only)IV. Use ‘Anova’ in ‘car’ package for same analyses, and also illustrateunbalanced mixed design.I. Bring in data and arrange for R to do analysis of variance (least squaresmethod).-- Notice that the data indicate the grouping by numbering the subjects sequentially from1 to 9, rather than from 1 to 3 within each Group.-- Notice that each observation is on a separate line.-- Make sure you make ‘subjects’ into a factor. If you don’t, R will treat it as a numericalvariable and you will get nonsense.> your.data=read.table(pipe("pbpaste"),header=T) # use this to copy from the clipboardinto R, OR use the method on the next line (but not both).Quick Look Summary of R Code for mixed designs:Using ‘aov’ for BALANCED designs only:> model=aov(dv~Betw*Within+Error(S / Within))Using ‘Anova’ in ‘car’ package (unbalanced in between-groups part of the design is ok):> multmodel=lm(cbind(dv1,dv2,dv3)~G) # G is a grouping factor> model1=Anova(multmodel,idata=your.factors,idesign=A*B,type=”III”) # make adataframe that lays out the order of the factors and use that as ‘idata’, A and B are repeatedmeasures factors> summary (model1, multivariate=F)610 R12 Balanced Mixed Anova Prof Colleen MoorePsychology 610 UW—Madison2> your.data = read.table("r1data.txt", header=T) # first set the correct folder in R undereither ‘file’ or ‘Misc’ (see 610—R1), Then name the file you want to read in thisstatement by replacing “r1data.txt” with your data file name.> attach(your.data) # attaching data is convenient but can cause some problems. Thealternative is to tell R what variables to use with the ‘file$variable’ method.> your.data # we will use ‘temprtr’ as the DV. This example has blood pressure as acovariate in the original analysis in Winer. group subject treat bloodprs temprtr1 1 1 1 3 82 1 1 2 4 143 1 2 1 5 114 1 2 2 9 185 1 3 1 11 166 1 3 2 14 227 2 4 1 2 68 2 4 2 1 89 2 5 1 8 1210 2 5 2 9 1411 2 6 1 10 912 2 6 2 9 1013 3 7 1 7 1014 3 7 2 4 1015 3 8 1 8 1416 3 8 2 10 1817 3 9 1 9 1518 3 9 2 12 22> G=factor(group) # make factors> T=factor(treat)> S=factor(subject) # make subjects (the variable indicating observation units) into afactor !!!II. The Anova of the data, make graphs etc.A. Carry out anova using ‘aov’> model2=aov(temprtr~G*T+Error(S/T)) # G*T indicates we want the full model withinteractions. The question is how to tell R the right error term to use. Because we wantSxT as the error for T and GxT, we say that T is nested in S. Right, T is nested insubjects.> summary(model2)Error: S # this is the ‘Between’ part of the design Df Sum Sq Mean Sq F value Pr(>F)G 2 100.0 50.0 1.6949 0.2609Residuals 6 177.0 29.5Error: S:T ## this is the ‘Within’ part of the design Df Sum Sq Mean Sq F value Pr(>F)T 1 68.056 68.056 31.4103 0.001375 **G:T 2 16.444 8.222 3.7949 0.086064 .Residuals 6 13.000 2.167---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1610 R12 Balanced Mixed Anova Prof Colleen MoorePsychology 610 UW—Madison3** Check the dfs to make sure that R has the right error terms for the model you intendto run!! There are lots of ways to run this model incorrectly. Here’s my mentalscratchwork on the dfs:1--Total observations = 18 in this example. Sum of df (without the intercept)should be 17, and it is.2--Df for error for G (the ‘between’ part of the design) should be (in Keppel’snotation) S/G, or #cells(n-1). We have 3 levels of G (#cells in the between part of thedesign), and we have 3 people per cell, so df = 6 is correct.3-- For the “Within” part of the design, the error df should be (in Keppel’snotation) T x S/G, or (t –1) (n – 1) (#cells). Because we have two levels of factor T, thenthis df should also = 6. Dfs are as we want.** Check that the data are balanced!!Copy just the data and factors to a new data frame, then test that data frame forbalance (this is because I made new variables for the factors, rather than just turning‘group’ and ‘treat’ and ‘subject’ into factors themselves).> same.data=data.frame(G,T,S,temprtr)> !is.list(replications(temprtr~G*T, data=same.data)) # omit the error part of the model inasking R about balance.[1] TRUEB. Obtain means, se’s and estimated effects, make some graphs1. Means, se’s, estimated effects> model.tables(model2,se=T)Tables of effects GG 1 2 3 1.667 -3.333 1.667 TT 1 2-1.9444 1.9444 G:T TG 1 2 1 -1.2222 1.2222 2 1.1111 -1.1111 3 0.1111 -0.1111Standard errors of effects G T G:T 2.2174 0.4907 0.8498replic. 6 9 3Warning messages:1: In if (se) if (type == "effects" && is.list(n)) { :610 R12 Balanced Mixed Anova Prof Colleen MoorePsychology 610 UW—Madison4 the condition has length > 1 and only the first element will be used2: In if (se) result$se <- se.tables : the condition has length > 1 and only the first element will be usedR’s estimated se’s


View Full Document
Download Mixed Anova, One Factor Between, One Within
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Mixed Anova, One Factor Between, One Within and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Mixed Anova, One Factor Between, One Within 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?