EDUC/PSY 6600: Unit 3 Homework: Your Name Spring 2018
EDUC/PSY 6600: Unit 3 Homework: Your Name Spring 2018
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
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
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
Paired t-test
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
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
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.
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
19
Summary Statistics
id
1
130
2
3
4
blood_pressure
120 5
6
7
8
110 9
10
11
12
100
20
124
blood_pressure
120
116
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
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
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)
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
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
32
Summary Statistics
7 id
1
2
recall
6 3
4
5
6
5
33
7.0
6.5
recall
6.0
5.5
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
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
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
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
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
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
48
Summary Statistics
20
15
completed
type_task
clerical
mechanical
10
49
20
15
completed
type_task
clerical
mechanical
10
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
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
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)
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
58
# Mixed ANOVA: post hoc pairwise tests <-- 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
60
Summary Statistics
10
jitter(longest_correct)
8
damage
left
none
right
6
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
64
# Mixed ANOVA: post hoc pairwise tests <-- 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
70
# Mixed ANOVA: post hoc pairwise tests <-- genderF
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