CU ASwR Lab07 Sol

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

JTMS-03 Applied Statistics with R

Spring Semester 2023

Lab 07 – Repeated-measures ANOVA – Solution


March 21, 2023

You research how the GPA of Bachelor students enrolled at a US American university develops over
the first three semesters of their studies. In your analyses you additionally take into account students’
biological sex and the intensity of their student job. Using the provided dataset, you test the following
hypotheses:
(H1) Semester GPA has been on the rise over the course of the first three semesters.
(H2) Semester GPA differs for male and female students.
(H3) Semester GPA differs with respect to the intensity of the job.

Data UniGPA.sav
Source Utrecht University

Variables (only the relevant ones)


student Unique identifier of the students
sex Students’ biological sex (1 = male, 2 = female)
job Intensity of students’ job over the course of the three semesters (1 = no job, 2 = 3-5 hours a
week, 3 = 5-10 hours a week)
gpa_1/2/3 Students’ GPA (US American grading system) in the respective semester

Reading the data into R

setwd("Type/your/directory/here")
library(foreign)
dataWide <- read.spss("UniGPAw.sav",
header= T, to.data.frame= T, use.value.labels= F,
use.missings= T)
attach(dataWide)

Tasks

1. Discuss:
a) the level of measurement of GPA, biological sex and job intensity.

The level of measurement of GPA is of interval quality, that of biological sex is nominal, whereas that
of job intensity is ordinal.

b) the appropriate statistical model for testing the hypotheses.

The hypotheses involve the analysis of a repeated measure, namely – GPA of the same students as
recorded in each of the first three semesters of their Bachelor studies. The development of students’
GPA in the period of observation is expected to differ by semester (within-subjects factor), biological
sex (between-subjects factor) and job intensity (between-subjects factor). Therefore, the appropriate
statistical model is a mixed-design repeated-measures ANOVA.

c) which is the dependent variable and which are the independent ones in the model.

The dependent variable is semester GPA. The independent variables are semester, biological sex and
job intensity.

1
2. Data preparation
a) If needed, set the data to the appropriate format for the analysis.

The original format of the data is wide. In order to perform a (mixed-design) repeated-measures ANOVA
in R, the data need to be reshaped to a long format.

dataLong <- reshape(dataWide, direction="long",


idvar= "student", timevar= "semester",
varying= c("gpa_1","gpa_2","gpa_3"), v.names= "gpa")
dataLong <- dataLong[order(dataLong$student), ]

detach(dataWide)
attach(dataLong)

b) Prepare the variables for the analysis, where applicable.

fsemester <- factor(semester)


fsex <- factor(sex, levels= c(1,2), labels= c("male","female"))
fjob <- factor(job, levels= c(1,2,3), labels= c("no job","3-5 hrs","5-10 hrs"))

dataLong <- data.frame(dataLong, fsemester, fsex, fjob)

3. Test the hypotheses. Stick to the 5 % level of significance.


a) Specify the statistical model.

options(scipen= 10, digits= 2)

library(ez)
ex1 <- ezANOVA(dv= .(gpa), wid= .(student), within= .(fsemester),
between= .(fjob, fsex), detailed= T, type= 3, data= dataLong)
print(ex1)
## $ANOVA
## Effect DFn DFd SSn SSd F p p<.05 ges
## 1 (Intercept) 1 194 2504.239 31 15589.83 2.8e-187 * 0.98207
## 2 fjob 2 194 9.317 31 29.00 9.6e-12 * 0.16925
## 3 fsex 1 194 2.422 31 15.08 1.4e-04 * 0.05029
## 5 fsemester 2 388 9.863 15 131.33 2.8e-44 * 0.17740
## 4 fjob:fsex 2 194 0.200 31 0.62 5.4e-01 0.00436
## 6 fjob:fsemester 4 388 1.287 15 8.57 1.2e-06 * 0.02737
## 7 fsex:fsemester 2 388 0.206 15 2.74 6.6e-02 0.00448
## 8 fjob:fsex:fsemester 4 388 0.044 15 0.29 8.8e-01 0.00095
##
## $`Mauchly's Test for Sphericity`
## Effect W p p<.05
## 5 fsemester 0.67 1.1e-17 *
## 6 fjob:fsemester 0.67 1.1e-17 *
## 7 fsex:fsemester 0.67 1.1e-17 *
## 8 fjob:fsex:fsemester 0.67 1.1e-17 *
##
## $`Sphericity Corrections`
## Effect GGe p[GG] p[GG]<.05 HFe p[HF] p[HF]<.05
## 5 fsemester 0.75 6.1e-34 * 0.75 3.9e-34 *
## 6 fjob:fsemester 0.75 1.8e-05 * 0.75 1.7e-05 *
## 7 fsex:fsemester 0.75 8.1e-02 0.75 8.1e-02
## 8 fjob:fsex:fsemester 0.75 8.3e-01 0.75 8.3e-01

2
b) Can sphericity be assumed? If not, outline your strategy to deal with the issue.

According to the result of Mauchly’s test (W = 0.67, p < 0.01), the assumption of sphericity in repeated-
measures ANOVA cannot be supported with the data at hand. In order to account for this issue, the
reporting (and interpretation) of the results will draw on the probabilities of the within-subjects effects
as adjusted on the basis of the conservative Greenhouse-Geisser correction to the degrees of freedom.

c) Describe on the basis of descriptive statistics how students’ GPA develops across the three
semesters, across the three semesters for male and female students, and across the three
semesters with respect to job intensity. Use appropriate graphs to visualize the evidence.

Students’ GPA has been on the rise in the course of the first three semesters of their Bachelor studies.
From an average of 2.6 in the first semester, GPA rose to an average of 2.9 in the second semester
and increased again to an average of 3.1 in the third semester.

library(psych)
describeBy(gpa, fsemester, mat= T, digits= 2)
## group1 n mean sd median min max range skew kurtosis se
## X11 1 200 2.6 0.27 2.6 2.0 3.6 1.6 0.30 0.43 0.02
## X12 2 200 2.9 0.32 2.9 2.1 3.9 1.8 0.04 -0.24 0.02
## X13 3 200 3.1 0.36 3.0 2.2 4.0 1.8 0.20 -0.30 0.03

The upward trend in semester GPA is depicted in the mean plot below.

library(gplots)
plotmeans(gpa ~ fsemester, col= 4, lwd= 2, ylim= c(1,4),
ylab= "Semester GPA", xlab= "Semester")

According to the descriptive evidence, the upward trend in semester GPA is present for both male and
female students. As to male students, GPA increased from an average of 2.6 in the first semester to
2.8 in the second semester, reaching on average 3.0 in the third semester. For female students, GPA
increased from an average of 2.7 in the first semester to 2.9 in the second semester and 3.2 in the third
one. Though consistently on the rise in both groups, the GPA of male students remains lower than that
of their female counterparts in each semester. Moreover, the gender gap in favor of the female students
tends to grow over time.

3
describeBy(gpa, fsemester:fsex, mat= T, digits= 2)
## group1 n mean sd median min max range skew kurtosis se
## X11 1:male 95 2.6 0.25 2.6 2.0 3.3 1.3 0.20 -0.03 0.03
## X12 1:female 105 2.7 0.27 2.7 2.0 3.6 1.6 0.31 0.59 0.03
## X13 2:male 95 2.8 0.32 2.8 2.1 3.5 1.4 0.19 -0.61 0.03
## X14 2:female 105 2.9 0.31 3.0 2.2 3.9 1.6 -0.03 0.30 0.03
## X15 3:male 95 3.0 0.35 3.0 2.2 3.9 1.6 0.28 -0.56 0.04
## X16 3:female 105 3.2 0.33 3.1 2.4 4.0 1.6 0.29 -0.11 0.03

The development of semester GPA in the groups of male and female students is depicted in the
interaction plot below.

interaction.plot(x.factor= fsemester, trace.factor= fsex, response= gpa,


col= 4:2, lwd=2, ylim= c(1,4),
ylab= "Semester GPA", xlab= "Semester")

Further, the upward trend in semester GPA is evident for each of the three levels of job intensity. In
each of the three semesters, GPA remains consistently highest for the students who do not have a job,
followed by those who work 3-5 hours a week, with those who work 5-10 hours a week having the
relatively lowest GPA. Moreover, the gap between the three groups of students, as defined by job
intensity, becomes larger with time, with students who do not have a job experiencing the steepest
increase.

describeBy(gpa, fsemester:fjob, mat= T, digits= 2)

## group1 n mean sd median min max range skew kurtosis se


## X11 1:no job 22 2.8 0.24 2.8 2.1 3.2 1.10 -0.75 0.81 0.05
## X12 1:3-5 hrs 148 2.7 0.27 2.6 2.0 3.6 1.60 0.46 0.58 0.02
## X13 1:5-10 hrs 30 2.5 0.23 2.5 2.0 2.9 0.90 -0.16 -0.84 0.04
## X14 2:no job 22 3.2 0.28 3.2 2.6 3.9 1.25 0.27 0.09 0.06
## X15 2:3-5 hrs 148 2.9 0.30 2.9 2.2 3.7 1.50 -0.13 -0.32 0.02
## X16 2:5-10 hrs 30 2.6 0.25 2.6 2.1 3.0 0.90 0.07 -1.02 0.05
## X17 3:no job 22 3.4 0.32 3.4 2.9 4.0 1.10 0.39 -0.99 0.07
## X18 3:3-5 hrs 148 3.1 0.34 3.1 2.2 3.9 1.65 -0.07 -0.39 0.03
## X19 3:5-10 hrs 30 2.8 0.17 2.8 2.3 3.0 0.75 -0.63 0.29 0.03

4
The interaction plot below depicts the development of semester GPA for the levels of job intensity.

interaction.plot(x.factor= fsemester, trace.factor= fjob, response= gpa,


col= 4:2, lwd=2, ylim= c(1,4),
ylab= "Semester GPA", xlab= "Semester")

d) Report and interpret the test results regarding hypothesis H1. Comment also the size of the
effect. If needed, use a post-hoc test with the Bonferroni correction.

The descriptive evidence points to an upward trend in GPA across the three semesters. The ANOVA
test informs that the development over time, as captured by the effect of the within-subjects factor
semester, is highly significant: F (1.50, 291) = 131.33, p < 0.01. A post-hoc test with the Bonferroni
correction (see below) reveals that the observed change in GPA between any two semesters is highly
significant (p < 0.01). Thus, the data provide empirical support for hypothesis H1. The effect can be
considered large, as indicated by the generalized eta squared measure (ges; η2 = 0.18).

pairwise.t.test(gpa, fsemester, paired= T, p.adjust.method= "bonferroni" )


##
## Pairwise comparisons using paired t tests
##
## data: gpa and fsemester
##
## 1 2
## 2 <2e-16 -
## 3 <2e-16 <2e-16
##
## P value adjustment method: bonferroni

e) Report and interpret the test results regarding hypotheses H2 and H3. Comment also on the
size of the effects.

As to hypothesis H2, the effect of the between-subjects factor sex on the within-subjects variability in
GPA is not statistically significant at the 5 % level: F (1.50, 291) = 2.74, p = 0.08. The ANOVA test
renders the observed differences in GPA between male and female students across the three
semesters as not meaningful from a statistical perspective. This is also reflected in the size of the effect

5
at stake – as indicated by the generalized eta squared measure, the effect is virtually ‘nil’ (η2 < 0.01).
Hypothesis H2 cannot be supported with the data.

Regarding hypothesis H3, the effect of the between-subjects factor job intensity on the within-subjects
variability in GPA is statistically significant: F (3, 291) = 8.57, p < 0.01. Thus, there are substantial
differences in semester GPA with respect to students’ job intensity, although the size of the effect in
question is small (η2 = 0.03). Hypothesis H3 can be supported with the data.

You might also like