PRE is called partial R-squared in regression, and partial
Eta-squared in ANOVA. This vignette will examine their equivalence using
the internal data depress.
depress collected depression,
gender, and class at Time 1. Traditionally, we
examine the effect of gender and class using
anova. We firstly let R know gender and class
are factors (i.e., categorical variables). Then we conduct anova using
car::Anova() and compute partial Eta-squared using
effectsize::eta_squared().
# factor gender and class
depress_factor <- depress
depress_factor$class <- factor(depress_factor$class, labels = c(3,5,9,12))
depress_factor$gender <- factor(depress_factor$gender, labels = c(0,1))
anova.fit <- lm(dm1 ~ gender + class, depress_factor)
Anova(anova.fit, type = 3)
#> Anova Table (Type III tests)
#>
#> Response: dm1
#> Sum Sq Df F value Pr(>F)
#> (Intercept) 67.166 1 464.5565 <2e-16 ***
#> gender 0.025 1 0.1758 0.6760
#> class 0.729 3 1.6808 0.1768
#> Residuals 12.868 89
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
cat("\n\n")
print(eta_squared(Anova(anova.fit, type = 3), partial = TRUE), digits = 6)
#> # Effect Size for ANOVA (Type III)
#>
#> Parameter | Eta2 (partial) | 95% CI
#> -------------------------------------------------
#> gender | 0.001972 | [0.000000, 1.000000]
#> class | 0.053619 | [0.000000, 1.000000]
#>
#> - One-sided CIs: upper bound fixed at [1.000000].Then we conduct regression analysis and compute PRE. For
class with four levels: 3, 5, 9, and 12, we dummy-code it
using ifelse() with the class12 as the reference group.
# class3 indicates whether the class is class3
depress$class3 <- ifelse(depress$class == 3, 1, 0)
# class5 indicates whether the class is class5
depress$class5 <- ifelse(depress$class == 5, 1, 0)
# class9 indicates whether the class is class9
depress$class9 <- ifelse(depress$class == 9, 1, 0)We compute the PRE of gender though comparing
Model A with gender against Model C without
gender.
fitC <- lm(dm1 ~ class3 + class5 + class9, depress)
fitA <- lm(dm1 ~ class3 + class5 + class9 + gender, depress)
print(compare_lm(fitC, fitA), digits = 3)
#> Baseline C A A vs. C
#> SSE 13.6 12.8932 12.8678 0.02542
#> df 93.0 90.0000 89.0000 1.00000
#> Number of parameters 1.0 4.0000 5.0000 1.00000
#> R_squared NA 0.0530 0.0549 0.00187
#> f_squared NA 0.0560 0.0581 0.00198
#> R_squared_adj NA 0.0214 0.0124 NA
#> PRE NA 0.0530 0.0549 0.00197
#> F(PA-PC,n-PA) NA 1.6791 1.2917 0.17583
#> p NA 0.1771 0.2794 0.67599
#> PRE_adj NA 0.0214 0.0124 -0.00924
#> power_post NA 0.4263 0.3887 0.06993Compare gender’s PRE and partial Eta-squared. They should be equal.
We compute the PRE of class. Note that in
regression, the PRE of class is the PRE
of all class’s dummy codes: class3,
class5, and class9.
fitC <- lm(dm1 ~ gender, depress)
fitA <- lm(dm1 ~ class3 + class5 + class9 + gender, depress)
print(compare_lm(fitC, fitA), digits = 3)
#> Baseline C A A vs. C
#> SSE 13.6 13.59681 12.8678 0.7291
#> df 93.0 92.00000 89.0000 3.0000
#> Number of parameters 1.0 2.00000 5.0000 3.0000
#> R_squared NA 0.00132 0.0549 0.0535
#> f_squared NA 0.00132 0.0581 0.0567
#> R_squared_adj NA -0.00953 0.0124 NA
#> PRE NA 0.00132 0.0549 0.0536
#> F(PA-PC,n-PA) NA 0.12165 1.2917 1.6808
#> p NA 0.72805 0.2794 0.1768
#> PRE_adj NA -0.00953 0.0124 0.0217
#> power_post NA 0.06376 0.3887 0.4266Compare class’s PRE and partial Eta-squared. They should be equal.
We compute the PRE of the full model(Model A). The PRE (partial R-squared or partial Eta-squared) of the full model is commonly known as the R-squared or Eta-squared of the full model.
fitC <- lm(dm1 ~ 1, depress)
fitA <- lm(dm1 ~ class3 + class5 + class9 + gender, depress)
print(compare_lm(fitC, fitA), digits = 3)
#> Baseline C A A vs. C
#> SSE 13.6 1.36e+01 12.8678 0.7470
#> df 93.0 9.30e+01 89.0000 4.0000
#> Number of parameters 1.0 1.00e+00 5.0000 4.0000
#> R_squared NA 6.52e-16 0.0549 0.0549
#> f_squared NA 6.66e-16 0.0581 0.0581
#> R_squared_adj NA 7.77e-16 0.0124 NA
#> PRE NA 6.66e-16 0.0549 0.0549
#> F(PA-PC,n-PA) NA NA 1.2917 1.2917
#> p NA NA 0.2794 0.2794
#> PRE_adj NA 6.66e-16 0.0124 0.0124
#> power_post NA NA 0.3887 0.3887As shown, the PRE of Model A against Model C is equal to Model A’s R_squared. Taken the loss of precision into consideration, Model C’s R_squared is zero.