0% found this document useful (0 votes)
11 views73 pages

EDUC/PSY 6600: Unit 3 Homework: Your Name Spring 2018

Uploaded by

admin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views73 pages

EDUC/PSY 6600: Unit 3 Homework: Your Name Spring 2018

Uploaded by

admin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

EDUC/PSY 6600: Unit 3 Homework

Your Name
Spring 2018

Contents
PREPARATION 3
Load Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Ihno’s Dataset for Section C’s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Other Datasets for Section B’s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Chapter 11. Matched pairs t-test 5


Section B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
11B-3 Matched Pairs vs. Direct Difference Methods . . . . . . . . . . . . . . . . . . . . . . . . 5
11B-6 Matched t-Test (1-sided) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
11B-8 Confidence Intervale for the Mean Difference . . . . . . . . . . . . . . . . . . . . . . . . 8
11B-9 t-Test for Mean Difference vs. Correlation . . . . . . . . . . . . . . . . . . . . . . . . . 10
Section C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
11C-1a. Matched pairs t-test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
11C-2. More than Two Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
11C-3. Compared to Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Chapter 15: Repeated Measures ANOVA 16


Section B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
audience_wide - Repeated Measures Design: Effect of Audience Size on Blood Pressure . . . 19
15B-3a/b/c RM ANOVA: no sphericity correction, but both effect sizes . . . . . . . . . . . . 22
15B-3c RM ANOVA: display all Sums-of-Squares components . . . . . . . . . . . . . . . . . . 23
15B-3d RM ANOVA: post hoc with Fisher’s LSD correction . . . . . . . . . . . . . . . . . . . 24
textbook_wide - Matched Design: Effect of Textbook on Student Quiz Scores . . . . . . . . 25
15B-4a RM ANOVA: display all Sums-of-Squares components . . . . . . . . . . . . . . . . . . 28
15B-4c RM ANOVA: GG correction for lack of sericity . . . . . . . . . . . . . . . . . . . . . . 29
15B-4d RM ANOVA: post-hoc with Tukey’s HSD correction . . . . . . . . . . . . . . . . . . . 30
15B-5a 1-Way ANOVA (treat studnets as independent) . . . . . . . . . . . . . . . . . . . . . 31
memory_wide - Repeated Measures Design: Stimuli’s Effect on Memory Recall . . . . . . . . . 32
15B-6a RM ANOVA: with sphericity test and corrections . . . . . . . . . . . . . . . . . . . . 35
15B-6b RM ANOVA: GG corretion for lack of sphericity . . . . . . . . . . . . . . . . . . . . . 36
15B-6d RM ANOVA: post-hoc with Fisher’s LDS correction . . . . . . . . . . . . . . . . . . . 37
Section C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
ihno_clean - Repeated Measures Design: Effect of Time (expereiment) on Anxiety levels
(performed INDEPENDENTLY by GENDER) . . . . . . . . . . . . . . . . . . . . . . 38
15C-1a RM ANOVA (twice): with sphericity test and corrections . . . . . . . . . . . . . . . . 38
15C-1b Paired t-Tests: choose 2 at a time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
ihno_clean - Repeated Measures Design: Effect of experiemnt (with vs without the experi-
mental item) on Stat Quiz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
15C-3 RM ANOVA vs. Paired t-test: only 2 groups . . . . . . . . . . . . . . . . . . . . . . . . 45

Chapter 16: Mixed Design ANOVA 47


Section B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Tutorial - Fitting Mixed Design ANOVA Models with afex::aov_4() . . . . . . . . . . . . . 47
tasks_wide - Repeated Measures and Assigned Group Design: Differential Effect of Music
on Production, by Task Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

1
16B-4a Mixed Design ANOVA: display all Sums-of-Squares components . . . . . . . . . . . . 51
16B-4b Mixed Design ANOVA: effect sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
anograms_wide -Repeated Measures and Assigned Group Design: Effect of Music and Task
Type on Production . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
16B-5b Mixed Design ANOVA: display all Sums-of-Squares components . . . . . . . . . . . . 56
16B-5c Mixed Design ANOVA: Main Effect’s post-hoc with appropriate correction . . . . . . 58
brain_wide - Repeated Measures and Observed Groups Design: Differential Effect of Stimuli
on Recall, by Brain Damage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
16B-8a-b Mixed Design ANOVA: with sphericity test and corrections . . . . . . . . . . . . . . 63
16B-8c Mixed Design ANOVA: Main Effect’s post-hoc with appropriate correction . . . . . . 64
Section C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
ihno_clean - Repeated Measures and Observed Group Design: Differential Effect of Time on
Anxiety, by Major . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
16c-1a Mixed Design ANOVA: with main effect post hocs . . . . . . . . . . . . . . . . . . . . 66
ihno_clean - Repeated Measures and Observed Group Design: Differential Effect of a Pop
Quiz (Time = Baseline, pre-quiz, post-quiz) on Heart Rate, by Gender . . . . . . . . . 68
16c-2a Mixed Design ANOVA: with main effect post hocs . . . . . . . . . . . . . . . . . . . . 68
ihno_clean - Repeated Measures and Assigned Group Design: Differential Effect of the Ex-
periemnt (Time = Pop Quiz vs. Standard Quiz) on Quiz Score, by Difficulty Level . . 72
16c-3a Mixed Design ANOVA: is there an interaction? . . . . . . . . . . . . . . . . . . . . . . 72

2
PREPARATION
Load Packages
• Make sure the packages are installed (Package tab)
library(tidyverse) # Loads several very helpful 'tidy' packages
library(readxl) # Read in Excel datasets
library(furniture) # Nice tables
library(educ6600) # data for Section B

Ihno’s Dataset for Section C’s


Import Data, Define Factors, and Compute New Variables
• Make sure the dataset is saved in the same folder as this file
• Make sure the that folder is the working directory
NOTE: I added the second line to convert all the variables names to lower case. I still kept the
F as a capital letter at the end of the five factor variables.
data_clean <- read_excel("Ihno_dataset.xls") %>%
dplyr::rename_all(tolower) %>%
dplyr::mutate(genderF = factor(gender,
levels = c(1, 2),
labels = c("Female",
"Male"))) %>%
dplyr::mutate(majorF = factor(major,
levels = c(1, 2, 3, 4,5),
labels = c("Psychology",
"Premed",
"Biology",
"Sociology",
"Economics"))) %>%
dplyr::mutate(reasonF = factor(reason,
levels = c(1, 2, 3),
labels = c("Program requirement",
"Personal interest",
"Advisor recommendation"))) %>%
dplyr::mutate(exp_condF = factor(exp_cond,
levels = c(1, 2, 3, 4),
labels = c("Easy",
"Moderate",
"Difficult",
"Impossible"))) %>%
dplyr::mutate(coffeeF = factor(coffee,
levels = c(0, 1),
labels = c("Not a regular coffee drinker",
"Regularly drinks coffee"))) %>%
dplyr::mutate(hr_base_bps = hr_base / 60) %>%
dplyr::mutate(anx_plus = rowsums(anx_base, anx_pre, anx_post)) %>%
dplyr::mutate(hr_avg = rowmeans(hr_base, hr_pre, hr_post)) %>%
dplyr::mutate(statDiff = statquiz - exp_sqz)

3
Other Datasets for Section B’s
data("schizo")
data("GRE")
data("test_scores")
data("child_vars")
data("memory")
data("data_wait")
data("data_food")
data("data_undergrad")
data("data_memory")
data("audience_wide")
data("textbook_wide")
data("memory_wide")
data("tasks_wide")
data("anograms_wide")
data("brain_wide")
data("coupleIQs")

4
Chapter 11. Matched pairs t-test
Section B
11B-3 Matched Pairs vs. Direct Difference Methods
TEXTBOOK QUESTION: Using the data from Exercise 9B6, which follows. (a) Determine whether
there is a significant tendency for verbal GRE scores to improve on the second testing. Calculate the matched
t in terms of the Pearson correlation coefficient already calculated for that exercise. (b) Recalculate the
matched t test according to the direct-difference method and compare the result to your answer for part a.
GRE

id verbalGRE_1 verbalGRE_2
1 1 540 570
2 2 510 520
3 3 580 600
4 4 550 530
5 5 520 520
DIRECTIONS: Calculate the matched pairs t test between verbalGRE_1and verbalGRE_2 in the GRE
dataset.
In order to use this function, you MUST first restructure your dataset so that the TWO continous variables
are stacked or gathered together. Use the tidyr::gather() function with the following FOUR options:
• A new variable name that will store the original variable names: key = new_group_var
• A new variable name that will store the original variable values: value = new_continuous_var
• List the original variable names: continous_var1, continuous_var2
• Do not get ride of blank values: na.rm = FALSE
After the dataset is fathered, ad the t.test() function, which needs at least THREE arguments:
• the formula: continuous_var ~ group_var
• the dataset: data = . we use the period to signify that the datset is being piped from above
• specify the data is paired: paired = TRUE the default is independent groups
Note: I suggest using key = time and value = verbalGRE.
# Paired t-test: verbalGRE1 & verbalGRE2

5
DIRECTIONS: Calculate a NEW variable called verbalGRE_diff with the dplyr::mutate() function by
subtracting the verbalGRE_1and verbalGRE_2 variables in the GRE dataset. Pipe it all together ans save it
as new dataset with the GRE_new <- assignment operator to use in the next step.
# Compute a new variable --> save as: child_new

Note: Remove the hashtag symbol at the first of the code line below to show your new variables.
# GRE_new

Note: Remember that before you do a one-sample t test for the mean, you have to use the
dplyr::pull() function (see chapter 6)
# 1-sample t test: pop mean of verbalGRE_diff = 0 (no difference)

6
11B-6 Matched t-Test (1-sided)
TEXTBOOK QUESTION: Do teenage boys tend to date teenage girls who have a lower IQ than they do?
To try to answer this question, 10 teenage couples (i.e., who are dating regularly) are randomly selected, and
each member of each couple is given an IQ test. The results are given in the following table (each column
represents a different couple):
coupleIQs

couple boy girl


1 1 110 105
2 2 100 108
3 3 120 110
4 4 90 95
5 5 108 105
6 6 115 125
7 7 122 118
8 8 110 116
9 9 127 118
10 10 118 126
TEXTBOOK QUESTION: Perform a one-tailed matched t test (α = .05) to determine whether the boys
have higher IQs than their girlfriends. What can you conclude?
NOTE: The homework skeleton shows the two-tailed test by mistake.
coupleIQs %>%
tidyr::gather(key = sex,
value = score,
boy, girl) %>%
t.test(score ~ sex,
data = .,
alternative = "greater",
paired = TRUE)

Paired t-test

data: score by sex


t = -0.25048, df = 9, p-value = 0.5961
alternative hypothesis: true difference in means is greater than 0
95 percent confidence interval:
-4.990976 Inf
sample estimates:
mean of the differences
-0.6

7
11B-8 Confidence Intervale for the Mean Difference
TEXTBOOK QUESTION: A cognitive psychologist is testing the theory that short-term memory is
mediated by subvocal rehearsal. This theory can be tested by reading aloud a string of letters to a participant,
who must repeat the string correctly after a brief delay. If the theory is correct, there will be more errors
when the list contains letters that sound alike (e.g., G and T) than when the list contains letters that look
alike (e.g., P and R). Each participant gets both types of letter strings, which are randomly mixed in the same
experimental session. The number of errors for each type of letter string for each participant are shown in
the following table. (a) Perform a matched t test ( α = .05, one tailed) on the data above and state your
conclusions. (b) Find the 95% confidence interval for the population difference for the two types of letters.
memory

id sound look
1 1 8 4
2 2 5 5
3 3 6 3
4 4 10 11
5 5 3 2
6 6 4 6
7 7 7 4
8 8 11 6
9 9 9 7
DIRECTIONS: Calculate the matched pairs t test between soundand look in the memory dataset twice:
first as a one-tail test and then again as a two-tailed* test.
Note: I suggest using key = type and value = errors.
# Paired t-test: sound and look --> ONE tail

8
# Paired t-test: sound and look --> TWO tails

9
11B-9 t-Test for Mean Difference vs. Correlation
TEXTBOOK QUESTION: For the data in Exercise 10B6: (a) Calculate the matched t value to test
whether there is a significant difference (α = .05, two tailed) between the spatial ability and math scores. Use
the correlation coefficient you calculated to find the regression slope in Exercise 10B6. (b) Explain how the
Pearson r for paired data can be very high and statistically significant, while the matched t test for the same
data fails to attain significance.
test_scores

id spatial math
1 1 13 19
2 2 32 25
3 3 41 31
4 4 26 18
5 5 28 37
6 6 12 16
7 7 19 14
8 8 33 28
9 9 24 20
10 10 46 39
11 11 22 21
12 12 17 15
DIRECTIONS: Calculate Pearson’s r between spatial and math in the schizo test_scores
# Pearson's r: spatial & math

10
Note: I suggest using key = type and value = score.
# Paired t-test: spatial & math

11
Section C
11C-1a. Matched pairs t-test
TEXTBOOK QUESTION: (a) Perform a matched-pairs t test to determine whether there is a significant
increase in heart rate from baseline to the prequiz measurement. (b) Repeat these paired t tests separately for
men and women.

Directions: Calculate the matched pairs t test between hr_baseand hr_pre Then repeat the calculation
TWICE more: first among just men and then for just women.
Note: Use the dplyr::filter() function to subset the sample BEFORE fitting the model.
Also, be aware of which type of variable you are using: genderF == "Male" or gender == 2
works, but gender == male does NOT.
Note: I suggest using key = time and value = hr.
# Paired t-test: hr_base & hr_pre <-- full sample

12
# Paired t-test: hr_base & hr_pre <-- subset of men

# Paired t-test: hr_base & hr_pre <-- subset of women

13
11C-2. More than Two Variables
TEXTBOOK QUESTION: (a) Perform a matched-pairs t test to determine whether there is a significant
increase in anxiety from baseline to the prequiz measurement. (b) Perform a matched-pairs t test to determine
whether there is a significant decrease in anxiety from the prequiz to the postquiz measurement.

Directions: Calculate the matched pairs t test first between anx_baseand anx_pre and then between
anx_preand anx_post.
Note: I suggest using key = time and value = anx.
# Paired t-test: anx_base & anx_pre

# Paired t-test: anx_pre & anx_post

14
11C-3. Compared to Correlation
TEXTBOOK QUESTION: Perform a matched-pairs t test to determine whether there is a significant
difference in mean scores between the experimental stats quiz and the regular stats quiz. Is the correlation
between the two quizzes statistically significant? Explain any discrepancy between the significance of the
correlation and the significance of the matched t test.

Directions: Calculate the matched pairs t test between exp_sqzand statquiz.


Note: I suggest using key = type and value = score.
# Paired t-test: exp_sqz & statquiz

Directions: Compute Pearson’s r: for exp_sqz and statquiz


# Pearson's r: exp_sqz & statquiz

15
Chapter 15: Repeated Measures ANOVA
Section B
Tutorial - Fitting RM ANOVA Models with afex::aov_4()
The aov_4() function from the afex package fits ANOVA models (oneway, two-way, repeated measures, and
mixed design). It needs at least two arguments:
1. formula: continuous_var ~ 1 + (RM_var|id_var) one observation per subject for each level of the
RMvar, so each id_var has multiple lines for each subject
2. dataset: data = . we use the period to signify that the datset is being piped from above
Here is an outline of what your syntax should look like when you fit and save a RM ANOVA. Of course
you will replace the dataset name and the variable names, as well as the name you are saving it as.
NOTE: The aov_4() function works on data in LONG format only. Each observation needs to
be on its one line or row with seperate variables for the group membership (categorical factor or
fct) and the continuous measurement (numberic or dbl).
# RM ANOVA: fit and save
aov_name <- data_name %>%
afex::aov_4(continuous_var ~ 1 + (RM_var|id_var),
data = .)

By running the name you saved you model under, you will get a brief set of output, including a measure of
Effect Size.
NOTE: The ges is the generalized eta squared. In a one-way ANOVA, the eta-squared effect
size is the same value, ie. generalized ηg and partial ηp are the same.
# Display basic ANOVA results (includes effect size)
aov_name

16
To fully fill out a standard ANOVA table and compute other effect sizes, you will need a more complete set
of output, including the Sum of Squares components, you will need to add summary() piped at the end of
the model name before running it or after the model with a pipe.
NOTE: IGNORE the first line that starts with (Intercept)! Also, the ‘mean sum of squares’
are not included in this table, nor is the Total line at the bottom of the standard ANOVA table.
You will need to manually compute these values and add them on the homework page. Remember
that Sum of Squares (SS) and degrees of freedom (df) add up, but Mean Sum of Squreas
(MS) do not add up. Also: MS = SS/df for each term.
This also runs and displays the results of Mauchly Tests for Sphericity, as well as the Greenhouse-Geisser
(GG) and Huynh-Feldt (HF) Corrections to the p-value.
NOTE: If the Mauchly’s p-value is bigger than .05, do not use the corrections. If Mauchly’s
p-value is less than .05, then apply the epsilon (eps or ϵ) to multiply the degree’s of freedom.
Yes, the df will be decimal numbers.
# Display fuller ANOVA results (sphericity tests)
summary(aov_name)

To see all the Sumes-of-Squared residuals for ALL of the model comoponents, you add $aov at the end of
the model name.
# Display all the sum of squares
aov_name$aov

Repeated Measures MANOVA Tests (Pillai test statistic) is computed is you add $Anova at the end of the
model name. This is a so called ‘Multivariate Test’. This is NOT what you want to do!
# Display fuller ANOVA results (includes sum of squares)
aov_name$Anova

17
If you only need to obtain the omnibus (overall) F-test without a correction for violation of sphericity, you
can add an option for correction = "none". You can also request both the generalized and partial η 2 effect
sizes with es = c("ges", "pes").
# RM ANOVA: no correction, both effect sizes
data_name %>%
afex::aov_4(continuous_var ~ 1 + (RM_var|id_var),
data = .,
anova_table = list(correction = "none",
es = c("ges", "pes")))

Post Hoc tests may be ran the same way as the 1 and 2-way ANOVAs from the last unit.
NOTE: Use Fisher’s LSD (adjust = "none") if the omnibus F-test is significant AND there
are THREE measurements per subject or block. Tukey’s HSD (adjust = "tukey") may be used
even if the F-test is not significant or if there are four or more repeated measures.
# RM ANOVA: post hoc all pairwise tests with Fisher's LSD correction
aov_name %>%
emmeans::emmeans(~ RM_var) %>%
pairs(adjust = "none")

# RM ANOVA: post hoc all pairwise tests with Tukey's HSD correction
aov_name %>%
emmeans::emmeans(~ RM_var) %>%
pairs(adjust = "tukey")

A means plot (model based), can help you write up your results.
NOTE: This zooms in on just the means and will make all differences seem significant, so make
sure to interpret it in conjunction with the ANOVA and post hoc tests.
# RM ANOVA: means plot
aov_name %>%
emmeans::emmip(~ RM_var)

18
audience_wide - Repeated Measures Design: Effect of Audience Size on Blood Pressure
TEXTBOOK QUESTION: A psychophysiologist wishes to explore the effects of public speaking on the
systolic blood pressure of young adults. Three conditions are tested. The subject must vividly imagine
delivering a speech to one person, to a small class of 20 persons, or to a large audience consisting of hundreds
of fellow students. Each subject has his or her systolic blood pressure measured (mmHg) under all three
conditions. Two subjects are randomly assigned to each of the six possible treatment orders. The data appear
in the following table:
id one twenty large
1 1 131 130 135
2 2 109 124 126
3 3 115 110 108
4 4 110 108 122
5 5 107 115 111
6 6 111 117 121
7 7 100 102 107
8 8 115 120 132
9 9 130 119 128
10 10 118 122 130
11 11 125 118 133
12 12 135 130 135

Restructure from wide to long format:


id audience blood_pressure
1 1 one 131
2 1 twenty 130
3 1 large 135
4 2 one 109
5 2 twenty 124
6 2 large 126
7 3 one 115
8 3 twenty 110
9 3 large 108
10 4 one 110
11 4 twenty 108
12 4 large 122
13 5 one 107
14 5 twenty 115
15 5 large 111
16 6 one 111
17 6 twenty 117
18 6 large 121
19 7 one 100
20 7 twenty 102

19
Summary Statistics

one twenty large


n = 12 n = 12 n = 12
blood_pressure
117.2 (10.9) 117.9 (8.4) 124.0 (10.3)

Profile Plots (raw data)

id
1
130
2
3
4
blood_pressure

120 5
6
7
8
110 9
10
11
12
100

one twenty large


audience
Means Plot (raw data)

20
124
blood_pressure

120

116

one twenty large


audience

21
15B-3a/b/c RM ANOVA: no sphericity correction, but both effect sizes
TEXTBOOK QUESTION: (a) Perform an RM ANOVA on the blood pressure data and write the results
in words, as they would appear in a journal article. Does the size of the audience have a significant effect on
blood pressure at the .05 level? (Hint : Subtract 100 from every entry in the preceding table before computing
any of the SS’s. This will make your work easier without changing any of the SS components or F ratios.)
(b) What might you do to minimize the possibility of carryover effects?
DIRECTIONS: Perform a Repeated Measures ANOVA for blood pressure under the three condiditons
to determine if the size of the imagine audience has an effect. Request no correction for violations of
sphericity (correction = "none") and both effect sizes (es = c("ges", "pes"). Save this model as a
name fit_audience and run the name (without $Anova) to see the brief output.
# RM ANOVA: no correction for lack of sphericity <-- NAME AND SAVE

22
15B-3c RM ANOVA: display all Sums-of-Squares components
2
TEXTBOOK QUESTION: (c) Calculate ηRM from the F ratio you calculated in part a. Does this look
like a large effect? How could this effect size be misleading in planning future experiments?
DIRECTIONS: Request all the Sums-of-Squares (SS’s) by adding $aov at the end of the model name
fit_audience.
# RM ANOVA: display all Sums-of-Squares components

23
15B-3d RM ANOVA: post hoc with Fisher’s LSD correction
TEXTBOOK QUESTION: (d) Test all the pairs of means with protected t tests using the error term
from the RM ANOVA. Which pairs differ significantly at the .01 level?
DIRECTIONS: Conduct all possible post hoc pairwise tests on fit_audience using Fisher’s LSD.
# RM ANOVA: post hoc all pairwise tests with Fisher's LSD correction

Means Plot (model based)


DIRECTIONS: Construct a means plot of fit_audience using emmeans::emmip(~ RM_var) to help in-
terpret the direction of any significant differences.
# RM ANOVA: means plot

24
textbook_wide - Matched Design: Effect of Textbook on Student Quiz Scores
TEXTBOOK QUESTION: A statistics professor wants to know if it really matters which textbook she
uses to teach her course. She selects four textbooks that differ in approach and then matches her 36 students
into blocks of four based on their similarity in math background and aptitude. Each student in each block is
randomly assigned to a different text. At some point in the course, the professor gives a surprise 20-question
quiz. The number of questions each student answers correctly appears in the following table:
block A B C D
1 1 17 15 20 18
2 2 8 6 11 7
3 3 6 5 10 6
4 4 12 10 14 13
5 5 19 20 20 18
6 6 14 13 15 15
7 7 10 7 14 10
8 8 7 7 11 6
9 9 12 11 15 13

Restructure from wide to long format:


id block book quiz
1 1 1 A 17
2 2 2 A 8
3 3 3 A 6
4 4 4 A 12
5 5 5 A 19
6 6 6 A 14
7 7 7 A 10
8 8 8 A 7
9 9 9 A 12
10 10 1 B 15
11 11 2 B 6
12 12 3 B 5
13 13 4 B 10
14 14 5 B 20
15 15 6 B 13
16 16 7 B 7
17 17 8 B 7
18 18 9 B 11
19 19 1 C 20
20 20 2 C 11

25
Summary Statistics

A B C D
n=9 n=9 n=9 n=9
quiz
11.7 (4.4) 10.4 (4.9) 14.4 (3.6) 11.8 (4.8)

Profile Plots (raw data)

20

block
1
2
15
3
4
quiz

5
6
10
7
8
9

A B C D
book
Means Plots (raw data)

26
16

14
quiz

12

10

A B C D
book

27
15B-4a RM ANOVA: display all Sums-of-Squares components
TEXTBOOK QUESTION: (a) Perform an RM ANOVA on the data, and present the results of your
ANOVA in a summary table. Does it make a difference which textbook the professor uses? (b) Considering
your answer to part a, what type of error could you be making (Type I or Type II)?
DIRECTIONS: Perform a Repeated Measures ANOVA for quiz scores under the four books to determine
if the text has an effect. Make sure to save your model (fit_textbook), so that you can add $aov at the
end of the name to extract all the Sums-of-Squares.
# RM ANOVA: display all Sums-of-Squares components

28
15B-4c RM ANOVA: GG correction for lack of sericity
TEXTBOOK QUESTION: (c) Would your F ratio from part a be significant at the .01 level if you were
to assume a maximum violation of the sphericity assumption? Explain.
DIRECTIONS: Run the name of the model fit_textbook alone to extract the adjusted degrees of freedom
and F-test. The sums-of-squares for the corrected test are the same as for the uncorrected you just did.
# RM ANOVA: GG correction for lack of sphericity

29
15B-4d RM ANOVA: post-hoc with Tukey’s HSD correction
TEXTBOOK QUESTION: (d) Test all the pairs of means with Tukey’s HSD, using the error term from
the RM ANOVA. Which pairs differ significantly at the .05 level?
DIRECTIONS: Conduct all possible post hoc pairwise tests on fit_audience using Tukey’s HSD.
# RM ANOVA: post hoc all pairwise tests with Tukey's HSD correction

Means Plot (model based)


DIRECTIONS: Construct a means plot of fit_audience using emmeans::emmip(~ RM_var) to help in-
terpret the direction of any significant differences.

30
15B-5a 1-Way ANOVA (treat studnets as independent)
TEXTBOOK QUESTION: (a) Perform a one-way independent-groups ANOVA on the data from Exercise
4.
DIRECTIONS: Perform the ANOVA with the book as an between-subjects factor, instead of a within-
subjects factor (ignoring matching) for quiz scores to determine if the text has an effect. Make sure to
save your model (fit_book1way), so that you can add $aov at the end of the name to extract all the
Sums-of-Squares.
# 1-way ANOVA: 1 between-subject factor

TEXTBOOK QUESTION: (b) Does choice of text make a significant difference when the groups of
subjects are considered to be independent (i.e., the matching is ignored)? (c) Comparing your solution to
this exercise with your solution to Exercise 4, which part of the F ratio remains unchanged? What can you
say about the advantages of matching in this case?

31
memory_wide - Repeated Measures Design: Stimuli’s Effect on Memory Recall
TEXTBOOK QUESTION: A neuropsychologist is exploring short-term memory deficits in people who
have suffered damage to the left cerebral hemisphere. He suspects that memory for some types of material will
be more affected than memory for other types. To test this hypothesis he presented six brain-damaged subjects
with stimuli consisting of strings of digits, strings of letters, and strings of digits and letters mixed. The
longest string that each subject in each stimulus condition could repeat correctly is presented in the following
table. (One subject was run in each of the six possible orders.)
id digit letter mixed
1 1 6 5 6
2 2 8 7 5
3 3 7 7 4
4 4 8 5 8
5 5 6 4 7
6 6 7 6 5

Restructure from wide to long format:


id stimuli recall
1 1 digit 6
2 1 letter 5
3 1 mixed 6
4 2 digit 8
5 2 letter 7
6 2 mixed 5
7 3 digit 7
8 3 letter 7
9 3 mixed 4
10 4 digit 8
11 4 letter 5
12 4 mixed 8
13 5 digit 6
14 5 letter 4
15 5 mixed 7
16 6 digit 7
17 6 letter 6
18 6 mixed 5

32
Summary Statistics

digit letter mixed


n=6 n=6 n=6
recall
7.0 (0.9) 5.7 (1.2) 5.8 (1.5)

Profile Plots (raw data)

7 id
1
2
recall

6 3
4
5
6
5

digit letter mixed


stimuli
Means Plots (raw data)

33
7.0

6.5
recall

6.0

5.5

digit letter mixed


stimuli

34
15B-6a RM ANOVA: with sphericity test and corrections
TEXTBOOK QUESTION: (a) Perform an RM ANOVA. Is your calculated F value significant at the
.05 level?
DIRECTIONS: Perform a Repeated Measures ANOVA for recall under the three stimuli to determine if
the type of stimuli has an effect. Save it as the name fit_memory and then use the summary() function
display additional output.
# RM ANOVA: Mauchle Tests for Sphericity and Corrections applied

35
15B-6b RM ANOVA: GG corretion for lack of sphericity
TEXTBOOK QUESTION: (b) Would your conclusion in part a change if you could not assume that
sphericity exists in the population underlying this experiment? Explain. (c) Based on the graph you drew of
these data for Exercise 15A2, would you say that the RM ANOVA is appropriate for these data? Explain.
DIRECTIONS: Run the name of the model fit_memory alone to extract the adjusted degrees of freedom
and F-test. The sums-of-squares for the corrected test are the same as for the uncorrected you just did.
# RM ANOVA: GG correction for lack of sphericity

36
15B-6d RM ANOVA: post-hoc with Fisher’s LDS correction
TEXTBOOK QUESTION: (d) Test all the possible pairs of means with separate matched t tests (or
two-group RM ANOVAs) at the .01 level.
DIRECTIONS: Conduct all possible post hoc pairwise tests on fit_audience using Fisher’s LSD.
# RM ANOVA: post hoc all pairwise tests with Fisher's LSD correction

Means Plot (model based)


DIRECTIONS: Construct a means plot of fit_audience using emmeans::emmip(~ RM_var) to help in-
terpret the direction of any significant differences.
# RM ANOVA: means plot

37
Section C
ihno_clean - Repeated Measures Design: Effect of Time (expereiment) on Anxiety levels (per-
formed INDEPENDENTLY by GENDER)
15C-1a RM ANOVA (twice): with sphericity test and corrections
TEXTBOOK QUESTION: (a) Use Split File to perform separate RM ANOVAs for men and women
to test for a significant change in anxiety level over time (baseline, prequiz, and postquiz). Use Options to
request pairwise tests. Write up the results in APA style.
data_clean %>%
dplyr::select(sub_num, anx_base, anx_pre, anx_post) %>%
head(n = 4)

# A tibble: 4 x 4
sub_num anx_base anx_pre anx_post
<dbl> <dbl> <dbl> <dbl>
1 1 17 22 20
2 2 17 19 16
3 3 19 14 15
4 4 19 13 16
Restructure from wide to long format:
#Restructure: wide-to-long
ihno_anx_long <- data_clean %>%
tidyr::gather(key = variable,
value = anxiety,
anx_base, anx_pre, anx_post) %>%
dplyr::mutate(time = case_when(variable == "anx_base" ~ "baseline",
variable == "anx_pre" ~ "pre-quiz",
variable == "anx_post" ~ "post-quiz") %>%
factor(levels = c("baseline", "pre-quiz", "post-quiz"))) %>%
dplyr::arrange(sub_num, time)

ihno_anx_long %>%
dplyr::select(sub_num, time, anxiety) %>%
head(n = 12)

# A tibble: 12 x 3
sub_num time anxiety
<dbl> <fct> <dbl>
1 1 baseline 17
2 1 pre-quiz 22
3 1 post-quiz 20
4 2 baseline 17
5 2 pre-quiz 19
6 2 post-quiz 16
7 3 baseline 19
8 3 pre-quiz 14
9 3 post-quiz 15
10 4 baseline 19
11 4 pre-quiz 13
12 4 post-quiz 16

38
RESTRICT to just FEMALES
DIRECTIONS: Perform a Repeated Measures ANOVA for anxiety at all three time points to determine
if the experiment had an effect. Make sure to preceed the ANOVA with a dplyr::filter() step to restrict
to just genderF == "Female. Save it as the name fit_anx_female and then use the summary() function
display additional output.
# RM ANOVA: Mauchle Tests for Sphericity with and without corrections applied

39
DIRECTIONS: If, and only if, the omnibus F test yielded evidence of at least one time point having a
different average anxiety FOR WOMEN, follow up with post hoc pairs tests based on the ANOVA model.
# RM ANOVA: post hoc all pairwise tests with Fisher's LSD correction

Means Plot (model based)


DIRECTIONS: If, and only if, the omnibus F test yielded evidence of at least one time point having a
different average anxiety FOR WOMEN construct a means plot of fit_audience using emmeans::emmip(~
RM_var) to help interpret the direction of any significant differences.
# Means Plot: model based

40
RESTRICT to just MALES
DIRECTIONS: Perform a Repeated Measures ANOVA for anxiety at all three time points to determine
if the experiment had an effect. Make sure to preceed the ANOVA with a dplyr::filter() step to restrict
to just genderF == "Male. Save it as the name fit_anx_male and then use the summary() function display
additional output.
# RM ANOVA: Mauchle Tests for Sphericity with and without corrections applied

41
DIRECTIONS: If, and only if, the omnibus F test yielded evidence of at least one time point having a
different average anxiety FOR MEN, follow up with post hoc pairs tests based on the ANOVA model.
# RM ANOVA: post hoc all pairwise tests with Fisher's LSD correction

Means Plot (model based)


DIRECTIONS: If, and only if, the omnibus F test yielded evidence of at least one time point having
a different average anxiety FOR MEN, construct a means plot of fit_audience using emmeans::emmip(~
RM_var) to help interpret the direction of any significant differences.
# Means Plot: model based

42
15C-1b Paired t-Tests: choose 2 at a time
TEXTBOOK QUESTION: (b) Using ANALYZE/Compare Means , perform matched t tests for each
pair of RM levels, and then compare these p values to those produced in the Pairwise Comparisons results
box of the RM ANOVA.
DIRECTIONS: If, and only if, the omnibus F test yielded evidence of at least one time point having a
different average anxiety FOR WOMEN, follow up with post hoc pairs tests NOT based on the ANOVA
model. Instead, increase your dplyr::filter() to include requiring only 2 of the 3 time points (eg. time
%in% c("baseline", "pre-quiz")). You will have to do this 3 times, as there are three ways to choose a
pair from three options.
# Paired T-test: filter - women & baseline/pre-quiz

# Paired T-test: filter - women & baseline or post-quiz

# Paired T-test: filter - women & pre-quiz/post-quiz

43
DIRECTIONS: If, and only if, the omnibus F test yielded evidence of at least one time point having a
different average anxiety FOR MEN, follow up with post hoc pairs tests NOT based on the ANOVA model.
Instead, increase your dplyr::filter() to include requiring only 2 of the 3 time points (eg. time %in%
c("baseline", "pre-quiz")). You will have to do this 3 times, as there are three ways to choose a pair
from three options.
# Paired T-test: filter - men & baseline/pre-quiz

# Paired T-test: filter - men & baseline or post-quiz

# Paired T-test: filter - men & pre-quiz/post-quiz

44
ihno_clean - Repeated Measures Design: Effect of experiemnt (with vs without the experi-
mental item) on Stat Quiz
15C-3 RM ANOVA vs. Paired t-test: only 2 groups
TEXTBOOK QUESTION: Perform an RM ANOVA to determine whether there is a significant difference
in mean scores between the experimental stats quiz and the regular stats quiz. Compare this F ratio with the
matched t value you obtained from computer exercise #3 in Chapter 11.
Restructure: wide-to-long
data_clean %>%
dplyr::select(sub_num, statquiz, exp_sqz) %>%
head(n = 5)

# A tibble: 5 x 3
sub_num statquiz exp_sqz
<dbl> <dbl> <dbl>
1 1 6 7
2 2 9 11
3 3 8 8
4 4 7 8
5 5 6 6
ihno_statquiz_long <- data_clean %>%
tidyr::gather(key = variable,
value = s_quiz,
statquiz, exp_sqz) %>%
dplyr::mutate(time = case_when(variable == "statquiz" ~ "background",
variable == "exp_sqz" ~ "experimental") %>%
factor()) %>%
dplyr::arrange(sub_num, time)

ihno_statquiz_long %>%
dplyr::select(sub_num, time, s_quiz) %>%
head(n = 10)

# A tibble: 10 x 3
sub_num time s_quiz
<dbl> <fct> <dbl>
1 1 background 6
2 1 experimental 7
3 2 background 9
4 2 experimental 11
5 3 background 8
6 3 experimental 8
7 4 background 7
8 4 experimental 8
9 5 background 6
10 5 experimental 6

45
DIRECTIONS: Perform a Repeated Measures ANOVA for recall under the three stimuli to determine if
the type of stimuli has an effect. Do not save this model as a name; just run it without nameing/saving it.
NOTE: When the measure is only repeated twice, sphericity can not be violated, so no such test
are performed.
# RM ANOVA: no correction for lack of sphericity

DIRECTIONS: Alternatively, since there are only two measures, you can run this same analysis as a paired
t.test, using t.test(). Make sure you include paired = TRUE.
# Matched t-test: paired = TRUE

46
Chapter 16: Mixed Design ANOVA
Section B
Tutorial - Fitting Mixed Design ANOVA Models with afex::aov_4()
The aov_4() function from the afex package fits ANOVA models (oneway, two-way, repeated measures, and
mixed design). It needs at least two arguments:
1. formula: continuous_var ~ group_var + (RM_var|id_var) one observation per subject for each
level of the RMvar, so each id_var has multiple lines for each subject, each subject can only belong to
exactly one group./
2. dataset: data = . we use the period to signify that the datset is being piped from above
Here is an outline of what your syntax should look like when you fit and save a Mixed ANOVA. Of
course you will replace the dataset name and the variable names, as well as the name you are saving it as.
NOTE: The aov_4() function works on data in LONG format only. Each observation needs to
be on its one line or row with seperate variables for the group membership (categorical factor or
fct) and the continuous measurement (numberic or dbl).
# RM ANOVA: fit and save
aov_name <- data_name %>%
afex::aov_4(continuous_var ~ group_var + (RM_var|id_var),
data = .)

47
tasks_wide - Repeated Measures and Assigned Group Design: Differential Effect of Music on
Production, by Task Type
TEXTBOOK QUESTION: In Exercise 15B1, subjects performed a clerical task under three noise condi-
tions. Now suppose a new group of subjects is added to study the effects of the same three conditions on the
performance of a simpler, more mechanical task. The data from Exercise 15B1 follow, along with the data
for the mechanical task.
clerical_background clerical_popular clerical_metal
1 10 12 8
2 7 9 4
3 13 15 9
4 18 12 6
5 6 8 3
mechanical_background mechanical_popular mechanical_metal
1 15 18 20
2 19 22 23
3 8 12 15
4 10 10 14
5 16 19 19

id type_task noise completed


1 1 clerical background 10
2 2 clerical background 7
3 3 clerical background 13
4 4 clerical background 18
5 5 clerical background 6
6 1 clerical popular 12
7 2 clerical popular 9
8 3 clerical popular 15
9 4 clerical popular 12
10 5 clerical popular 8
11 1 clerical metal 8
12 2 clerical metal 4
13 3 clerical metal 9
14 4 clerical metal 6
15 5 clerical metal 3
16 6 mechanical background 15
17 7 mechanical background 19
18 8 mechanical background 8
19 9 mechanical background 10
20 10 mechanical background 16

48
Summary Statistics

type_task background metal popular


clerical 10.8 (4.87) 6 (2.55) 11.2 (2.77)
mechanical 13.6 (4.51) 18.2 (3.7) 16.2 (5.02)

Profile Plots (raw data)

20

15
completed

type_task
clerical
mechanical
10

background metal popular


noise
Means Plots (raw data)

49
20

15
completed

type_task
clerical
mechanical

10

background metal popular


noise

50
16B-4a Mixed Design ANOVA: display all Sums-of-Squares components
TEXTBOOK QUESTION: (a) Perform a mixed-design ANOVA, and display the results in a summary
table.
DIRECTIONS: Perform a Repeated Measures ANOVA for number of tasks completed under the four noise
conditions to see if there is an effect and if the effect is different dependtion on the type of task. Request no
correction for violations of sphericity (correction = "none") and both effect sizes (es = c("ges", "pes").
Make sure to save your model (fit_tasks), so that you can add $aov at the end of the name to extract all
the Sums-of-Squares.
# Mixed ANOVA: display all Sums-of-Squares components

51
16B-4b Mixed Design ANOVA: effect sizes
TEXTBOOK QUESTION: (b) Calculate generalized eta squared for the main effect of the type-of-task
factor. Does this look like a large effect size? Explain.
DIRECTIONS: Run the name of the model fit_tasks alone to extract the adjusted degrees of freedom
and F-test. The sums-of-squares for the corrected test are the same as for the uncorrected you just did.
# Mixed ANOVA: name the model was saved as

Means Plot (model based)


DIRECTIONS: Construct a means plot of fit_audience using emmeans::emmip(~ RM_var) to help in-
terpret the direction of any significant differences.
# RM ANOVA: means plot

52
anograms_wide -Repeated Measures and Assigned Group Design: Effect of Music and Task
Type on Production
TEXTBOOK QUESTION: Dr. Jones is investigating various conditions that affect mental effort- which,
in this experiment, involves solving anagrams. Subjects were randomly assigned to one of three experimental
conditions. Subjects in the first group were told that they would not be getting feedback on their performance.
Subjects in the second and third groups were told they would get feedback, but only subjects in the third group
were told (erroneously) that anagram solving was highly correlated with intelligence and creativity (Dr. Jones
hoped this information would produce ego involvement). The list of anagrams given to each subject contained
a random mix of problems at four levels of difficulty determined by the number of letters presented (five, six,
seven, or eight). The number of anagrams correctly solved by each subject in each condition and at each level
of difficulty is given in the following table:
anograms_wide

none_5 none_6 none_7 none_8 alone_5 alone_6 alone_7 alone_8 withEgo_5


1 9 6 4 2 19 16 15 12 30
2 10 7 4 3 19 15 11 11 31
3 12 9 7 5 22 20 17 14 34
withEgo_6 withEgo_7 withEgo_8
1 25 22 21
2 30 27 23
3 32 28 24

Restructure from wide to long format:


id feedback difficulty correct
1 1 none 5 9
2 2 none 5 10
3 3 none 5 12
4 1 none 6 6
5 2 none 6 7
6 3 none 6 9
7 1 none 7 4
8 2 none 7 4
9 3 none 7 7
10 1 none 8 2
11 2 none 8 3
12 3 none 8 5
13 4 alone 5 19
14 5 alone 5 19
15 6 alone 5 22
16 4 alone 6 16
17 5 alone 6 15
18 6 alone 6 20
19 4 alone 7 15
20 5 alone 7 11

53
Summary Statistics

feedback 5 6 7 8
alone 20 (1.73) 17 (2.65) 14.33 (3.06) 12.33 (1.53)
none 10.33 (1.53) 7.33 (1.53) 5 (1.73) 3.33 (1.53)
withEgo 31.67 (2.08) 29 (3.61) 25.67 (3.21) 22.67 (1.53)

Profile Plots (raw data)

30

feedback
20
correct

alone
none
withEgo

10

5 6 7 8
difficulty
Means Plots (raw data)

54
30

feedback
20
correct

alone
none
withEgo

10

5 6 7 8
difficulty

55
16B-5b Mixed Design ANOVA: display all Sums-of-Squares components
TEXTBOOK QUESTION: (b) Perform a mixed analysis of variance, and display the results in a summary
table. Would any of your conclusions change if you do not assume sphericity? Explain.
DIRECTIONS: Perform a Repeated Measures ANOVA for number of tasks completed under the four
noise conditions to see if there is an effect and if the effect is different dependtion on the type of task. Make
sure to save your model (fit_ano), so that you can add $aov at the end of the name to extract all the
Sums-of-Squares.
# Mixed ANOVA: display all Sums-of-Squares components

56
DIRECTIONS: Use the summary() function on the model name fit_ano to display the sphericity test
and corrections to answer the last portion of this question.
# Mixed ANOVA: sphericity tests and corrections

57
16B-5c Mixed Design ANOVA: Main Effect’s post-hoc with appropriate correction
TEXTBOOK QUESTION: (c) Perform post hoc pairwise comparisons for both main effects, using the
appropriate error term from part b in each case. Explain why these follow-up tests are appropriate given
your results in part b.
DIRECTIONS: Use the prior model fit_ano to run post hoc test for the levels of each main effect,
separately SINCE THE INTERACTION IS NOT SIGNIFICANT (including a means plot). Choose an
appropriate method to control type I errors when making multiple comparisons.
# Mixed ANOVA: post hoc pairwise tests <-- feedback

# RM ANOVA: means plot <--feedback

58
# Mixed ANOVA: post hoc pairwise tests <-- difficulty

# RM ANOVA: means plot <-- difficulty

59
brain_wide - Repeated Measures and Observed Groups Design: Differential Effect of Stimuli
on Recall, by Brain Damage
TEXTBOOK QUESTION: Exercise 15B6 described a neuropsychologist studying subjects with brain
damage to the left cerebral hemisphere. Such a study would probably include a group of subjects with damage
to the right hemisphere and a group of control subjects without brain damage. The data from Exercise 15B6
(the number of digit or letter strings each subject recalled) follow, along with data for the two comparison
groups just mentioned.
brain_wide

left_digit left_letter left_mixed right_digit right_letter right_mixed


1 6 5 6 9 8 6
2 8 7 5 8 8 7
3 7 7 4 9 7 8
4 8 5 8 7 8 8
5 6 4 7 7 6 7
6 7 6 5 9 8 9
none_digit none_letter none_mixed
1 8 8 7
2 10 9 9
3 9 10 8
4 9 7 9
5 8 8 8
6 10 10 9

Restructure from wide to long format:


id damage stimuli longest_correct
1 1 left digit 6
2 2 left digit 8
3 3 left digit 7
4 4 left digit 8
5 5 left digit 6
6 6 left digit 7
7 1 left letter 5
8 2 left letter 7
9 3 left letter 7
10 4 left letter 5
11 5 left letter 4
12 6 left letter 6
13 1 left mixed 6
14 2 left mixed 5
15 3 left mixed 4
16 4 left mixed 8
17 5 left mixed 7
18 6 left mixed 5
19 7 right digit 9
20 8 right digit 8

60
Summary Statistics

damage digit letter mixed


left 7 (0.89) 5.67 (1.21) 5.83 (1.47)
none 9 (0.89) 8.67 (1.21) 8.33 (0.82)
right 8.17 (0.98) 7.5 (0.84) 7.5 (1.05)

Profile Plots (raw data)

10
jitter(longest_correct)

8
damage
left
none
right
6

digit letter mixed


stimuli
Means Plots (raw data)

61
9

8
longest_correct

damage
left
none
7
right

5
digit letter mixed
stimuli

62
16B-8a-b Mixed Design ANOVA: with sphericity test and corrections
TEXTBOOK QUESTION: (a) Perform a mixed-design ANOVA and test the three F ratios at the .05
level. What can you conclude about the effects of brain damage on short-term recall for these types of stimuli?
(b) Draw a graph of these data, subject by subject. Do the assumptions of the mixed-design ANOVA seem
reasonable in this case? Explain.
DIRECTIONS: Perform a Repeated Measures ANOVA for longest correct recall under the various stimuli
to see if there is an effect and if the effect is different dependtion on brain damage. Make sure to save your
model (fit_brain), so that you can use the summary() function on the name to test for sphericity and make
appropriate corrections.
# Mixe ANOVA: with sphericity tests and corrections

63
16B-8c Mixed Design ANOVA: Main Effect’s post-hoc with appropriate correction
TEXTBOOK QUESTION: (c) Perform post hoc pairwise comparisons for both main effects. Do not
assume sphericity for the RM factor.
DIRECTIONS: Use the prior model fit_brain to run post hoc test for the levels of each main effect,
separately SINCE THE INTERACTION IS NOT SIGNIFICANT (including a means plot). Choose an
appropriate method to control type I errors when making multiple comparisons. (you do not need to worry
about sphericity)
# Mixed ANOVA: post hoc pairwise tests <-- damage

# RM ANOVA: means plot <-- damage

64
# Mixed ANOVA: post hoc pairwise tests <-- stimuli

# RM ANOVA: means plot <-- stimuli

65
Section C
ihno_clean - Repeated Measures and Observed Group Design: Differential Effect of Time on
Anxiety, by Major
16c-1a Mixed Design ANOVA: with main effect post hocs
TEXTBOOK QUESTION: (a) Perform a mixed-design ANOVA with the three anxiety measures as the
RM levels, and major as the between-subjects factor. Request a plot of the cell means, and post hoc tests for
both the RM factor (LSD) and for major (Tukey). Report the results of the ANOVA in APA style.
DIRECTIONS: Using the ihno_anx_long dataset from the chapter 15 questions, perform a Repeated
Measures ANOVA for at the three time points to see if the experiment had an effect on anxiety and if the
effect is different dependtion on major. Make sure to save your model (fit_anx_major), so that you can
use the summary() function on the name to test for sphericity and make appropriate corrections. Do specify
that you would like to display BOTH effect size measures with es = c("ges", "pes"), but do NOT include
correction = "none".
# Mixed ANOVA: with sphericity tests and corrections

66
DIRECTIONS: To display the effect size meausre, run the name (fit_anx_major) of the model alone.
# Mixed ANOVA: effect sizes

DIRECTIONS: SINCE THE INTERACTIONIS SIGNIFICANT, instead of focusing on the main effects
alone, plot the interaction with the emmeans::emmip(group_var ~ RM_var) function.
# Mixed ANOVA: means plot <-- interaction

67
ihno_clean - Repeated Measures and Observed Group Design: Differential Effect of a Pop
Quiz (Time = Baseline, pre-quiz, post-quiz) on Heart Rate, by Gender
16c-2a Mixed Design ANOVA: with main effect post hocs
TEXTBOOK QUESTION: (a) Perform a mixed-design ANOVA with the three heart-rate measures as
the RM levels and gender as the between-subjects factor. Request a plot of the cell means and post hoc tests
for the RM factor (LSD). Report the results of the ANOVA in APA style.
data_clean %>%
dplyr::select(sub_num, genderF, hr_base, hr_pre, hr_post) %>%
head(n = 4)

# A tibble: 4 x 5
sub_num genderF hr_base hr_pre hr_post
<dbl> <fct> <dbl> <dbl> <dbl>
1 1 Female 71 68 65
2 2 Female 73 75 68
3 3 Female 69 76 72
4 4 Female 72 73 78
Restructure from wide to long format:
#Restructure: wide-to-long
ihno_hr_long <- data_clean %>%
tidyr::gather(key = variable,
value = hr,
hr_base, hr_pre, hr_post) %>%
dplyr::mutate(time = case_when(variable == "hr_base" ~ "baseline",
variable == "hr_pre" ~ "pre-quiz",
variable == "hr_post" ~ "post-quiz") %>%
factor(levels = c("baseline", "pre-quiz", "post-quiz"))) %>%
dplyr::arrange(sub_num, time)

ihno_hr_long %>%
dplyr::select(sub_num, genderF, time, hr) %>%
head(n = 12)

# A tibble: 12 x 4
sub_num genderF time hr
<dbl> <fct> <fct> <dbl>
1 1 Female baseline 71
2 1 Female pre-quiz 68
3 1 Female post-quiz 65
4 2 Female baseline 73
5 2 Female pre-quiz 75
6 2 Female post-quiz 68
7 3 Female baseline 69
8 3 Female pre-quiz 76
9 3 Female post-quiz 72
10 4 Female baseline 72
11 4 Female pre-quiz 73
12 4 Female post-quiz 78

68
DIRECTIONS: Using the ihno_hr_long dataset just reformatted, perform a Repeated Measures ANOVA
for at the three time points to see if the experiment had an effect on heart rateand if the effect is different
dependtion on gender Make sure to save your model (fit_hr_major), so that you can use the summary()
function on the name to test for sphericity and make appropriate corrections. Do specify that you would
like to display BOTH effect size measures with es = c("ges", "pes"), but do NOT include correction
= "none".
# Mixe ANOVA: with sphericity tests and corrections

69
DIRECTIONS: Use the prior model fit_brain to run post hoc test for the levels of each main effect,
separately SINCE THE INTERACTION IS NOT SIGNIFICANT (including a means plot). Choose an
appropriate method to control type I errors when making multiple comparisons. (you do not need to worry
about sphericity)
# Mixed ANOVA: post hoc pairwise tests <-- damage

# RM ANOVA: means plot <-- damage

70
# Mixed ANOVA: post hoc pairwise tests <-- genderF

# RM ANOVA: means plot <-- stimuli

71
ihno_clean - Repeated Measures and Assigned Group Design: Differential Effect of the Ex-
periemnt (Time = Pop Quiz vs. Standard Quiz) on Quiz Score, by Difficulty Level
16c-3a Mixed Design ANOVA: is there an interaction?
TEXTBOOK QUESTION: (a) Perform a mixed-design ANOVA with the two 10-point quizzes (statquiz
and exp_sqz) as the RM levels, and exp_cond as the between-subjects factor. Request a plot of the cell means.
Report the results of the ANOVA in APA style. If the interaction is significant, explain the pattern you see
in the plot of the cell means.
DIRECTIONS: Using the ihno_statquiz_long dataset from the chapter 15 questions, perform a Repeated
Measures ANOVA for at the two quizes to see if the experiment had an effect on score and if the effect is
different dependtion on difficulty level. Make sure to save your model (fit_anx_major), so that you can use
the summary() function on the name to view the output. Do specify that you would like to display BOTH
effect size measures with es = c("ges", "pes"), but do NOT include correction = "none".
NOTE: When the measure is only repeated twice, sphericity can not be violated, so no such test
are performed.
# Mixed ANOVA: with summary

72
DIRECTIONS: SINCE THE INTERACTIONIS SIGNIFICANT, instead of focusing on the main effects
alone, plot the interaction with the emmeans::emmip(group_var ~ RM_var) function.
# RM ANOVA: means plot <-- interaction

73

You might also like