Title: | Residuals from Partial Regressions |
Version: | 0.2.0 |
Description: | Creates a data frame with the residuals of partial regressions of the main explanatory variable and the variable of interest. This method follows the Frisch-Waugh-Lovell theorem, as explained in Lovell (2008) <doi:10.3200/JECE.39.1.88-91>. |
License: | GPL (≥ 3) |
BugReports: | https://github.com/ropensci/partialling.out/issues/ |
Suggests: | tinytest, tinysnapshot, knitr, rmarkdown, palmerpenguins, tinytable, fwlplot, tsibble, units, purrr, fontquiver, rsvg, svglite |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
VignetteBuilder: | knitr |
Imports: | glue, lifecycle, rlang, fixest, lfe, stats, tinyplot |
URL: | https://docs.ropensci.org/partialling.out/, https://github.com/ropensci/partialling.out/ |
NeedsCompilation: | no |
Packaged: | 2025-10-12 18:55:10 UTC; marc |
Author: | Marc Bosch-Matas |
Maintainer: | Marc Bosch-Matas <mboschmatas@gmail.com> |
Depends: | R (≥ 4.1.0) |
Repository: | CRAN |
Date/Publication: | 2025-10-17 20:10:02 UTC |
partialling.out: Residuals from Partial Regressions
Description
Creates a data frame with the residuals of partial regressions of the main explanatory variable and the variable of interest. This method follows the Frisch-Waugh-Lovell theorem, as explained in Lovell (2008) doi:10.3200/JECE.39.1.88-91.
Author(s)
Maintainer: Marc Bosch-Matas mboschmatas@gmail.com (ORCID)
Other contributors:
Christian Testa (Christian reviewed the package (v. 0.1.1) for rOpenSci, see <https://github.com/ropensci/software-review/issues/703>) [reviewer]
Kyle Butts (Kyle reviewed the package (v. 0.1.1) for rOpenSci, see <https://github.com/ropensci/software-review/issues/703>) [reviewer]
Adam Loy (Adam reviewed the package (v. 0.1.1) for rOpenSci, see <https://github.com/ropensci/software-review/issues/703>) [reviewer]
See Also
Useful links:
Report bugs at https://github.com/ropensci/partialling.out/issues/
partialling_out: partialling out variable of interest and main
Description
Creates a data.frame of the residualised main explanatory variable and, if wanted, variable of interest of a linear or fixed effects model
Usage
partialling_out(model, data, weights, both, na.rm, ...)
Arguments
model |
object for which we want to residualise variables |
data |
data.frame used in the original model. Using different data will return unexpected results or an error. |
weights |
a numeric vector for weighting the partial models. Length must be
equal to number of rows of |
both |
if |
na.rm |
if |
... |
Any other lm, feols, or felm parameters that will be passed to the partial regressions |
Details
The function regresses the main (i.e. first in the model) explanatory
variable and the variable of interest (if parameter both
is set to TRUE
)
against all other control variables and fixed effects and returns the
residuals in a data.frame
Will accept lm, felm (lfe package), and feols (fixest package) objects
Value
a data.frame with the (residualised) variable of interest and residualised main explanatory variable
Examples
library(palmerpenguins)
library(fixest)
model <- feols(bill_length_mm ~ bill_depth_mm | species + island,
data = penguins)
partial_df <- partialling_out(model, penguins, both = TRUE)
plot_partial_residuals: scatterplot of partial residuals
Description
Function for plotting partial residuals
Uses tinyplot
as backend
Usage
plot_partial_residuals(x, add_lm = TRUE, quantile = FALSE, probs = 0.02, ...)
Arguments
x |
a partial_residuals objects from |
add_lm |
if TRUE, a |
quantile |
if TRUE, will plot only the mean values of the quantiles of the mean explanatory variable specified by |
probs |
numeric vector of length one that specifies the number of quantiles to be computed if |
... |
Any other |
Value
invisibly, x
Examples
library(palmerpenguins)
library(fixest)
model <- feols(bill_length_mm ~ bill_depth_mm | species + island,
data = penguins)
partial_df <- partialling_out(model, penguins, both = TRUE)
plot_partial_residuals(partial_df)