## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 6, fig.height = 4)

## ----setup--------------------------------------------------------------------
library(rifexpectile)

## -----------------------------------------------------------------------------
data(wage_gap_sim)
head(wage_gap_sim)

## -----------------------------------------------------------------------------
fit <- rif_decompose(
  logy ~ x1 + x2,
  data = wage_gap_sim,
  group = "group",
  ref_group = "2000",
  alpha = seq(0.1, 0.9, by = 0.2),
  boot_reps = 100,
  seed = 1
)
fit

## -----------------------------------------------------------------------------
plot(fit, which = "structure")

## -----------------------------------------------------------------------------
fit$detail_structure
colSums(fit$detail_structure)  # matches fit$structure

## -----------------------------------------------------------------------------
fit_w <- rif_decompose(
  logy ~ x1 + x2,
  data = wage_gap_sim,
  group = "group",
  ref_group = "2000",
  alpha = c(0.1, 0.5, 0.9),
  weights = "weight",
  boot_reps = 100,
  seed = 1
)
fit_w

## ----eval = requireNamespace("wooldridge", quietly = TRUE)--------------------
data(wage1, package = "wooldridge")
wage1$group <- ifelse(wage1$female == 1, "female", "male")

fit_gap <- rif_decompose(
  lwage ~ educ + exper + tenure,
  data = wage1,
  group = "group",
  ref_group = "male",
  alpha = c(0.1, 0.25, 0.5, 0.75, 0.9),
  boot_reps = 200,
  seed = 1
)
fit_gap

## ----eval = requireNamespace("wooldridge", quietly = TRUE)--------------------
plot(fit_gap, which = "structure")

## -----------------------------------------------------------------------------
str(simulate_income_data(n = 5, seed = 42))

