Package {feols.asv}


Type: Package
Title: Average Shared Variance (ASV) Decomposition for Multiple Fixed-Effects Models
Version: 0.0-1
Date: 2026-10-10
Depends: R (≥ 3.4.0),fixest,ggplot2,vegan
Maintainer: Jiangshan Lai <lai@njfu.edu.cn>
Description: Conducts average shared variance to calculate individual contributions of predictors (groups) towards within R2 for Multiple Fixed-Effects Models.
License: GPL-2 | GPL-3 [expanded from: GPL]
Encoding: UTF-8
RoxygenNote: 7.3.1
NeedsCompilation: no
Packaged: 2026-10-10 14:15:58 UTC; lai
Author: Jiangshan Lai ORCID iD [aut, cre]
Repository: CRAN
Date/Publication: 2026-10-21 14:50:08 UTC

Average Shared Variance (ASV) Decomposition for Two-Way Fixed-Effects Models Estimated with 'fixest::feols'

Description

Average Shared Variance (ASV) Decomposition for Two-Way Fixed-Effects Models Estimated with 'fixest::feols'

Usage

feols.asv(mod, iv = NULL, commonality = FALSE)

Arguments

mod

A fitted 'fixest' model estimated using 'fixest::feols'. The model must include at least one fixed effect and should contain at least two explanatory variables unless predictor groups are supplied through 'iv'.

iv

Optional named list defining groups of explanatory variables. Each element should contain the names of one or more predictors in the model. ASV contributions are calculated for the specified predictor groups. If 'NULL' (default), predictors are evaluated individually.

commonality

Logical. If 'TRUE', return the commonality decomposition for all non-empty combinations of predictors or predictor groups. If 'FALSE' (default), return the ASV decomposition.

Details

This function implements the average shared variance (ASV) approach for linear models fitted with 'fixest::feols', including models with two-way fixed effects. It fits all non-empty combinations of explanatory variables (or groups) while retaining the fixed effects specified in the original model, and uses each model's within \(R^2\) to quantify explained variation.

ASV allocates explained variation among predictors by assigning shared fractions equally among the predictors involved in each fraction. The resulting individual contributions are additive and order-independent; their sum equals the full model's within \(R^2\), subject to numerical precision and model-estimation constraints. This provides an interpretable allocation of explained variation when predictors share explanatory information.

The optional 'commonality = TRUE' output provides the underlying commonality decomposition, partitioning explained variation into unique and shared fractions. Negative commonality fractions can occur.

Interaction terms are not currently supported. The model formula must include at least one fixed effect, and the data used to fit the model must be available when the function is called.

Value

A list of class 'feolsasv' containing:

Within.R2

Within \(R^2\) of the full model.

hierarchical.partitioning

ASV contributions for each predictor or predictor group, including unique contribution, allocated shared contribution, total individual contribution, and percentage of total explained variation. This legacy component name is retained for compatibility.

commonality.analysis

When 'commonality = TRUE', a matrix reporting the commonality fraction and its percentage of the total for each non-empty predictor combination, plus a total row.

variables

Names of the predictors or predictor groups analysed.

type

Indicates whether ASV or commonality analysis was returned.

decomposition.error

Difference between the sum of commonality fractions and the full model's within \(R^2\).

Author(s)

Jiangshan Lai lai@njfu.edu.cn

References

Examples

library(fixest)

# Use base_did, a balanced panel dataset supplied with fixest.
# It contains 104 individuals observed over 10 periods.
data("base_did", package = "fixest")

# Create the treatment-by-post interaction used in a difference-in-differences
# model. The main effects of treat and post are absorbed by id and period
# fixed effects, respectively.
base_did$did <- base_did$treat * base_did$post

# Estimate a two-way fixed-effects model.
mod <- feols(y ~ x1 + did | id + period,
             data = base_did, cluster = ~id)

# Average shared variance (ASV) decomposition of within R-squared.
asv <- feols.asv(mod)
asv

# Optional commonality decomposition.
ca <- feols.asv(mod, commonality = TRUE)
ca

# Evaluate grouped predictor contributions.
iv <- list(Control = "x1", Treatment = "did")
feols.asv(mod, iv = iv)

Plot for a feols.asv object

Description

Plot for a feols.asv object

Usage

## S3 method for class 'feolsasv'
plot(x, plot.perc = FALSE, color = NULL, n = 1, dig = 4, ...)

Arguments

x

A feols.asv object.

plot.perc

Logical;if TRUE, the bar plot (based on ggplot2 package) of the percentage to individual effects of variables or groups towards total explained variation, the default is FALSE to show plot with original individual effects.

color

Color of variables.

n

Integer; which marginal R2 in output of r.squaredGLMM to plot.

dig

Integer; number of decimal places in Venn diagram.

...

unused

Value

a ggplot object

Author(s)

Jiangshan Lai lai@njfu.edu.cn