PRE is called partial R-squared in regression, and partialEta-squared in ANOVA. This vignette will examine their equivalence usingthe internal datadepress.
depress collecteddepression,gender, andclass at Time 1. Traditionally, weexamine the effect ofgender andclass usinganova. We firstly let R knowgender andclassare factors (i.e., categorical variables). Then we conduct anova usingcar::Anova() and compute partial Eta-squared usingeffectsize::eta_squared().
# factor gender and classdepress_factor<- depressdepress_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 ' ' 1cat("\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 computePRE. Forclass with four levels: 3, 5, 9, and 12, we dummy-code itusingifelse() with the class12 as the reference group.
# class3 indicates whether the class is class3depress$class3<-ifelse(depress$class==3,1,0)# class5 indicates whether the class is class5depress$class5<-ifelse(depress$class==5,1,0)# class9 indicates whether the class is class9depress$class9<-ifelse(depress$class==9,1,0)We compute thePRE ofgender though comparingModel A withgender against Model C withoutgender.
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#> n 94.0 94.0000 94.0000 94.00000#> Number of parameters 1.0 4.0000 5.0000 1.00000#> df 93.0 90.0000 89.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’sPRE and partial Eta-squared. They should beequal.
We compute thePRE ofclass. Note that inregression, thePRE ofclass is thePREof allclass’s dummy codes:class3,class5, andclass9.
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#> n 94.0 94.00000 94.0000 94.0000#> Number of parameters 1.0 2.00000 5.0000 3.0000#> df 93.0 92.00000 89.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’sPRE and partial Eta-squared. They should beequal.
We compute thePRE of the full model(Model A). ThePRE (partial R-squared or partial Eta-squared) of the fullmodel is commonly known as the R-squared or Eta-squared of the fullmodel.
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#> n 94.0 9.40e+01 94.0000 94.0000#> Number of parameters 1.0 1.00e+00 5.0000 4.0000#> df 93.0 9.30e+01 89.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, thePRE of Model A against Model C is equal toModel A’s R_squared. Taken the loss of precision into consideration,Model C’s R_squared is zero.