View source: R/sensitivity_stats.R
partial_r2 | R Documentation |
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(...)
## S3 method for class 'lm'
partial_r2(model, covariates = NULL, ...)
## S3 method for class 'fixest'
partial_r2(model, covariates = NULL, ...)
## S3 method for class 'numeric'
partial_r2(t_statistic, dof, ...)
partial_f2(...)
## S3 method for class 'numeric'
partial_f2(t_statistic, dof, ...)
## S3 method for class 'lm'
partial_f2(model, covariates = NULL, ...)
## S3 method for class 'fixest'
partial_f2(model, covariates = NULL, ...)
partial_f(...)
## S3 method for class 'fixest'
partial_f(model, covariates = NULL, ...)
## S3 method for class 'lm'
partial_f(model, covariates = NULL, ...)
## S3 method for class 'numeric'
partial_f(t_statistic, dof, ...)
## S3 method for class 'numeric'
partial_f(t_statistic, dof, ...)
## Default S3 method:
partial_r2(model, ...)
... |
arguments passed to other methods. First argument should either be an |
model |
an |
covariates |
model covariates for which the partial R2 will be computed. Default is to compute the partial R2 of all covariates. |
t_statistic |
|
dof |
residual degrees of freedom of the regression |
A numeric vector with the computed partial R2, f2, or f.
Cinelli, C. and Hazlett, C. (2020), "Making Sense of Sensitivity: Extending Omitted Variable Bias." Journal of the Royal Statistical Society, Series B (Statistical Methodology).
# 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")
## partial R2 of female with the outcome
partial_r2(model, covariates = "female")
# you can also provide the statistics directly
partial_r2(t_statistic = 4.18445, dof = 783)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.