MyNixOS website logo
Description

Scatter Plot After Residualizing Using 'fixest' Package.

Creates a scatter plot after residualizing using a set of covariates. The residuals are calculated using the 'fixest' package which allows very fast estimation that scales. Details of the (Yule-)Frisch-Waugh-Lovell theorem is given in Basu (2023) <doi:10.48550/arXiv.2307.00369>.

fwlplot

This is a super simple package to help make scatter plots of two variables after residualizing by covariates. This package uses fixest so things are super fast. This is meant to (as much as possible) be a drop in replacement for fixest::feols. You should be able to replace feols with fwl_plot and get a plot.

Installation

The stable version of fwlplot is available on CRAN.

install.packages("fwlplot")

Or, you can grab the latest development version from GitHub.

# install.packages("remotes")
remotes::install_github("kylebutts/fwlplot")

Example

Here’s a simple example with fixed effects removed by fixest.

library(fwlplot)
library(fixest)

flights <- data.table::fread("https://raw.githubusercontent.com/Rdatatable/data.table/master/vignettes/flights14.csv")
flights[, long_distance := distance > 2000]
# Sample 10000 rows
sample <- flights[sample(.N, 10000)]
# Without covariates = scatterplot
fwl_plot(dep_delay ~ air_time, data = sample)
# With covariates = FWL'd scatterplot
fwl_plot(
  dep_delay ~ air_time | origin + dest,
  data = sample, vcov = "hc1"
)

Plot random sample

If you have a large dataset, we can plot a sample of points with the n_sample argument. This determines the number of points per plot (see multiple estimation below).

fwl_plot(
  dep_delay ~ air_time | origin + dest,
  # Full dataset for estimation, 1000 obs. for plotting
  data = flights, n_sample = 1000
)

Full feols compatability

This is meant to be a 1:1 drop-in replacement with fixest, so everything should work by just replacing feols with

feols(
  dep_delay ~ air_time | origin + dest,
  data = sample, subset = ~long_distance, cluster = ~origin
)
#> OLS estimation, Dep. Var.: dep_delay
#> Observations: 1,746
#> Subset: long_distance
#> Fixed-effects: origin: 2,  dest: 15
#> Standard-errors: Clustered (origin) 
#>          Estimate Std. Error t value Pr(>|t|) 
#> air_time 0.081485   0.052053 1.56541   0.3619 
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> RMSE: 39.9     Adj. R2: 0.005478
#>              Within R2: 0.001048
fwl_plot(
  dep_delay ~ air_time | origin + dest,
  data = sample, subset = ~long_distance, cluster = ~origin
)

Multiple estimation

# Multiple y variables
fwl_plot(
  c(dep_delay, arr_delay) ~ air_time | origin + dest,
  data = sample
)
# `split` sample
fwl_plot(
  c(dep_delay, arr_delay) ~ air_time | origin + dest,
  data = sample, split = ~long_distance, n_sample = 1000
)
# `fsplit` = `split` sample and Full sample
fwl_plot(
  c(dep_delay, arr_delay) ~ air_time | origin + dest,
  data = sample, fsplit = ~long_distance, n_sample = 1000
)

ggplot2

library(ggplot2)
theme_set(theme_grey(base_size = 16))
fwl_plot(
  c(dep_delay, arr_delay) ~ air_time | origin + dest,
  data = sample, fsplit = ~long_distance,
  n_sample = 1000, ggplot = TRUE
)
Metadata

Version

0.3.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows