The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Package {fairlieR}


Title: Fairlie Decomposition for Nonlinear Models (Logit Models)
Version: 0.1.1
Description: Performs the Fairlie decomposition for nonlinear models (logit models). This function breaks down the difference in average outcomes between two groups into the part explained by group differences in observable characteristics and the unexplained part (Fairlie 1999 <doi:10.1086/209914>; Fairlie 2005 <doi:10.3233/JEM-2005-0259>).
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
Depends: R (≥ 3.5)
LazyData: true
Suggests: ggplot2
URL: https://github.com/CathyBu9/fairlieR
BugReports: https://github.com/CathyBu9/fairlieR/issues
NeedsCompilation: no
Packaged: 2026-07-15 15:36:40 UTC; yan
Author: Xinyan Bu [aut, cre]
Maintainer: Xinyan Bu <xinyan.bu@outlook.com>
Repository: CRAN
Date/Publication: 2026-07-23 13:10:02 UTC

Fairlie Decomposition for Binary Outcomes

Description

Performs the Fairlie decomposition for nonlinear models (logit models). This function breaks down the difference in average outcomes between two groups into the part explained by group differences in observable characteristics and the unexplained part (Fairlie 1999 https://doi.org/10.1086/209914; Fairlie 2005 https://doi.org/10.3233/JEM-2005-0259). Supports multiple reference coefficient weighting schemes.

Usage

fairlieR(
  formula,
  data,
  group,
  base_group = 0,
  reference = 0,
  reps = 100,
  ro = FALSE,
  seed = NULL,
  plot = FALSE,
  plot_color = c("#1F77B4", "#BDC3C7"),
  plot_show_title = TRUE,
  plot_show_subtitle = TRUE,
  verbose = TRUE
)

Arguments

formula

An object of class "formula" (e.g., Y ~ X1 + X2).

data

A data frame containing the variables in the model.

group

A character string specifying the grouping variable.

base_group

The value of the grouping variable used as the baseline for the difference. Default is 0.

reference

Determines the coefficients used for decomposition. Options:

  • 0 the value of base_group (Y=0),

  • 1 the value of the Y=1 group,

  • 0.5 (Reimers 1983: equally weighted),

  • "cotton" (Cotton 1988: sample size weighted),

  • -1 (Neumark 1988: pooled regression excluding group indicator),

  • -2 (Jann 2008: pooled regression including group indicator). Default is 0.

reps

An integer specifying the number of random permutations. Default is 100.

ro

A logical value. If TRUE, randomizes the ordering of variables. Default is FALSE.

seed

An optional integer to set the random seed for reproducibility.

plot

A logical value. If TRUE, generates an academic forest plot. Default is FALSE.

plot_color

A character vector of length 2 specifying fill colors for significant and non-significant variables. Default is c("#1F77B4", "#BDC3C7").

plot_show_title

A logical value. If TRUE, displays the main title on the plot. Default is TRUE.

plot_show_subtitle

A logical value. If TRUE, displays the subtitle (reference method) on the plot. Default is TRUE.

verbose

A logical value. If TRUE, prints the decomposition summary to the console. Default is TRUE.

Value

A data frame containing the decomposition results.

Author(s)

Xinyan Bu

References

Examples


# Load the embedded Stata example dataset
data("homecomp")

# Filter the data exactly as in the Stata example: if white==1|black==1
df_subset <- subset(homecomp, white == 1 | black == 1)

# Align factor levels and establish baselines
df_subset$educ_factor <- as.factor(
   ifelse(df_subset$college == 1, "College",
   ifelse(df_subset$somecol == 1, "SomeCol",
   ifelse(df_subset$hsgrad == 1, "HSGrad", "DropOut")))
)
df_subset$educ_factor <- relevel(df_subset$educ_factor, ref = "DropOut")

df_subset$marstat_factor <- as.factor(
   ifelse(df_subset$married == 1, "Married",
   ifelse(df_subset$prevmar == 1, "PrevMar", "Single"))
)
df_subset$marstat_factor <- relevel(df_subset$marstat_factor, ref = "Single")

# Run the native R Fairlie decomposition with visualization enabled
result <- fairlieR(homecomp ~ female + age + educ_factor + marstat_factor,
                   data = df_subset,
                   group = "black",
                   base_group = 0,
                   reference = -2,
                   reps = 100,
                   plot = TRUE)


Home Ownership Data from Stata

Description

An example dataset from Stata's fairlie module used to demonstrate the decomposition.

Usage

homecomp

Format

A data frame containing variables for home ownership, gender, age, education, and marital status.

Source

http://fmwww.bc.edu/RePEc/bocode/h/homecomp.dta

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.