1. Data Import and Preparation
The dataset requires one categorical independent variable (IV), one
continuous dependent variable (DV), and one continuous covariate. R
requires explicit declaration of categorical variables as factors.
# Read the SPSS dataset
data <- read_sav("Stalkers_Practice.sav")
# Ensure treatment is treated as a factor and labels are applied
data <- data %>%
mutate(treatment = as_factor(treatment))
# Set orthogonal contrasts for accurate Type III SS computation
options(contrasts = c("contr.sum", "contr.poly"))
Descriptive Statistics
Participants, prior to receiving Psychdyshamic Therapy, stalked on
average 65 hours per week. After recieving treatment, they stalked on
average 61.8 hours per week. Participants prior to participating in
Cruel to be Kind Therapy stalked on average 64.8 hours and stalked on
average 55 hours per week after receiving treatment.
by(data, data$treatment, summary)
## data$treatment: Psychodyshamic Therapy
## treatment stalk1 stalk2
## Psychodyshamic Therapy :25 Min. :45.00 Min. :45
## Cruel to be Kind Therapy: 0 1st Qu.:57.00 1st Qu.:56
## Median :66.00 Median :63
## Mean :66.04 Mean :63
## 3rd Qu.:70.00 3rd Qu.:69
## Max. :92.00 Max. :83
## ------------------------------------------------------------
## data$treatment: Cruel to be Kind Therapy
## treatment stalk1 stalk2
## Psychodyshamic Therapy : 0 Min. :45.00 Min. :12
## Cruel to be Kind Therapy:25 1st Qu.:57.00 1st Qu.:49
## Median :64.00 Median :59
## Mean :64.68 Mean :55
## 3rd Qu.:73.00 3rd Qu.:63
## Max. :84.00 Max. :78
2. Assumption 1: Independence of IV and Covariate
The covariate (stalk1) and the IV (treatment) must be independent.
This is evaluated using a standard one-way ANOVA.
# One-way ANOVA to test if pre-treatment stalking differs by treatment group
model_ind <- aov(stalk1 ~ treatment, data = data)
summary(model_ind)
## Df Sum Sq Mean Sq F value Pr(>F)
## treatment 1 23 23.12 0.183 0.671
## Residuals 48 6078 126.63
# Note: Non-significant F-test indicates the assumption is met.
3. Assumption 2: Homogeneity of Regression Slopes
The relationship between the covariate and the DV must be consistent
across all levels of the IV. This requires testing the interaction
term.
# Visualizing the regression lines per group [cite: 288]
ggplot(data, aes(x = stalk1, y = stalk2, color = treatment)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "Time Spent Stalking Before Therapy (hours per week)",
y = "Time Spent Stalking After Therapy (hours per week)") +
theme_minimal()

# Building the custom model with the interaction term [cite: 528]
model_slopes <- lm(stalk2 ~ stalk1 * treatment, data = data)
# Use Type III Sums of Squares via the car package
Anova(model_slopes, type = 3)
## Anova Table (Type III tests)
##
## Response: stalk2
## Sum Sq Df F value Pr(>F)
## (Intercept) 53.3 1 0.5570 0.45926
## stalk1 3945.2 1 41.2335 6.746e-08 ***
## treatment 274.7 1 2.8711 0.09695 .
## stalk1:treatment 161.1 1 1.6841 0.20084
## Residuals 4401.2 46
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Note: A non-significant interaction (stalk1:treatment) indicates the assumption is met[cite: 564].
4. Assumption 3: Homogeneity of Variance
Testing the null hypothesis that the error variance of the dependent
variable is equal across groups.
# Levene's Test
leveneTest(stalk2 ~ treatment, data = data, center = mean)
## Levene's Test for Homogeneity of Variance (center = mean)
## Df F value Pr(>F)
## group 1 2.2956 0.1363
## 48
# Note: If significant (p < .05), the assumption is violated. Proceed with robust methods if necessary.
5. Main Analysis: The ANCOVA Model
Run the full factorial model excluding the interaction term.
# Building the ANCOVA model
model_ancova <- lm(stalk2 ~ stalk1 + treatment, data = data)
# Standard SPSS output uses Type III Sum of Squares
ancova_results <- Anova(model_ancova, type = 3)
print(ancova_results)
## Anova Table (Type III tests)
##
## Response: stalk2
## Sum Sq Df F value Pr(>F)
## (Intercept) 69.9 1 0.7198 0.40049
## stalk1 3831.6 1 39.4725 1.004e-07 ***
## treatment 596.3 1 6.1434 0.01684 *
## Residuals 4562.4 47
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
6. Effect Sizes
Extracting Partial Eta Squared (\(\eta_{p}^{2}\)) for both the covariate and
the independent variable.
eta_squared(model_ancova, partial = TRUE)
## # Effect Size for ANOVA (Type I)
##
## Parameter | Eta2 (partial) | 95% CI
## -----------------------------------------
## stalk1 | 0.47 | [0.30, 1.00]
## treatment | 0.12 | [0.01, 1.00]
##
## - One-sided CIs: upper bound fixed at [1.00].
7. Estimated Marginal Means
The estimated marginal means are calculated from the linear model,
adjusting the group means to the mean level of the covariate.
# Calculate EM Means at the mean of the covariate
em_means <- emmeans(model_ancova, ~ treatment)
print(em_means)
## treatment emmean SE df lower.CL upper.CL
## Psychodyshamic Therapy 62.5 1.97 47 58.5 66.4
## Cruel to be Kind Therapy 55.5 1.97 47 51.6 59.5
##
## Confidence level used: 0.95
# Pairwise comparisons (Post-hoc)
pairs(em_means, adjust = "bonferroni")
## contrast estimate SE df t.ratio
## Psychodyshamic Therapy - Cruel to be Kind Therapy 6.92 2.79 47 2.479
## p.value
## 0.0168
8. Visualizing Estimated Marginal Means
# Plotting the adjusted means with 95% Confidence Intervals [cite: 784, 789]
emmip(model_ancova, ~ treatment, CIs = TRUE) +
labs(y = "Estimated Marginal Means", x = "Treatment Group") +
theme_minimal()

Interpretation:
Assumptions for the ANCOVA were met. Stalking behavior prior to
receiving treatment was statistically significant (F = 50.5, P
<.001). Treatment significantly decreased average hours each week
spent stalking (F = 5.5, p < .05). The estimated marginal means
indicate that the Cruel to Be Kind Treatment had a lesser effect (EM =
55.3) than the Psychdyshamic Therapy (EM = 61.5), as visualized in the
graphs. These outcomes suggest that Psychodyshamic Therapy is more
impactful on reducing stalking behaviors than Cruel to Be Kind
Treatment.
Response: stalk2
Sum Sq Df F value Pr(>F)
(Intercept) 0.0 1 0.0005 0.9815
stalk1 4430.6 1 50.5179 6.285e-09 ***
treatment 148.3 1 1.6912 0.1999
stalk1:treatment 77.3 1 0.8816 0.3527
Residuals 4034.4 46