PRE

library(Keng)
library(effectsize)
library(car)
#> Loading required package: carData
data("depress")

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)
format(compare_lm(fitC, fitA), digits = 3, nsmall = 3)
#>             SSE     df R_squared R_squared_adj     PRE F(PA-PC,n-PA)     p
#> Model C 12.8932 90.000   0.05300        0.0214      NA            NA    NA
#> Model A 12.8678 89.000   0.05487        0.0124      NA            NA    NA
#> A vs. C  0.0254  1.000   0.00187            NA 0.00197         0.176 0.676
#>          PRE_adj
#> Model C       NA
#> Model A       NA
#> A vs. C -0.00924

Compare 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)
format(compare_lm(fitC, fitA), digits = 3, nsmall = 3)
#>            SSE     df R_squared R_squared_adj    PRE F(PA-PC,n-PA)     p
#> Model C 13.597 92.000   0.00132      -0.00953     NA            NA    NA
#> Model A 12.868 89.000   0.05487       0.01239     NA            NA    NA
#> A vs. C  0.729  3.000   0.05355            NA 0.0536         1.681 0.177
#>         PRE_adj
#> Model C      NA
#> Model A      NA
#> A vs. C  0.0217

Compare 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)
format(compare_lm(fitC, fitA), digits = 3, nsmall = 3)
#>            SSE     df R_squared R_squared_adj    PRE F(PA-PC,n-PA)     p
#> Model C 13.615 93.000  6.52e-16      7.77e-16     NA            NA    NA
#> Model A 12.868 89.000  5.49e-02      1.24e-02     NA            NA    NA
#> A vs. C  0.747  4.000  5.49e-02            NA 0.0549         1.292 0.279
#>         PRE_adj
#> Model C      NA
#> Model A      NA
#> A vs. C  0.0124

As 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.