These functions computes the partial R2 and the partial (Cohen's) f2 for a linear regression model. The partial R2 describes how much of the residual variance of the outcome (after partialing out the other covariates) a covariate explains.

The partial R2 can be used as an extreme-scenario sensitivity analysis to omitted variables. Considering an unobserved confounder that explains 100% of the residual variance of the outcome, the partial R2 describes how strongly associated with the treatment this unobserved confounder would need to be in order to explain away the estimated effect. For details see Cinelli and Hazlett (2020).

The partial (Cohen's) f2 is a common measure of effect size (a transformation of the partial R2) that can also be used directly for sensitivity analysis using a bias factor table.

The function partial_r2 computes the partial R2. The function partial_f2 computes the partial f2 and the function partial_f the partial f. They can take as input an lm object or you may pass directly t-value and degrees of freedom.

For partial R2 of groups of covariates, check group_partial_r2.

partial_r2(model, ...)

# S3 method for lm
partial_r2(model, covariates = NULL, ...)

# S3 method for fixest
partial_r2(model, covariates = NULL, ...)

# S3 method for numeric
partial_r2(t_statistic, dof, ...)

partial_f2(model, ...)

# S3 method for numeric
partial_f2(t_statistic, dof, ...)

# S3 method for lm
partial_f2(model, covariates = NULL, ...)

# S3 method for fixest
partial_f2(model, covariates = NULL, ...)

partial_f(...)

Arguments

model

an fixest object with the regression model

...

arguments passed to other methods. First argument should either be an lm model or a fixest model with the regression model or a numeric vector with the t-value of the coefficient estimate

covariates

model covariates for which the partial R2 will be computed. Default is to compute the partial R2 of all covariates.

t_statistic

numeric vector with the t-value of the coefficient estimates

dof

residual degrees of freedom of the regression

Value

A numeric vector with the computed partial R2, f2, or f.

References

Cinelli, C. and Hazlett, C. (2020), "Making Sense of Sensitivity: Extending Omitted Variable Bias." Journal of the Royal Statistical Society, Series B (Statistical Methodology).

Examples


# using an lm object
## loads data
data("darfur")

## fits model
model <- lm(peacefactor ~ directlyharmed + age + farmer_dar + herder_dar +
             pastvoted + hhsize_darfur + female + village, data = darfur)

## partial R2 of the treatment (directly harmed) with the outcome (peacefactor)
partial_r2(model, covariates = "directlyharmed")
#> directlyharmed 
#>     0.02187309 

## partial R2 of female with the outcome
partial_r2(model, covariates = "female")
#>    female 
#> 0.1090339 

# you can also provide the statistics directly
partial_r2(t_statistic = 4.18445, dof = 783)
#> [1] 0.02187309