gen_densities: Generate Density Estimates for a 'quantileplot'

View source: R/gen_densities.R

gen_densitiesR Documentation

Generate Density Estimates for a quantileplot

Description

Estimate the conditional density of the outcome at at particular values of the predictor. These conditional densities appear as vertical slices in the output of quantileplot. This function is typically called indirectly via a user call to quantileplot.

Usage

gen_densities(
  data,
  slice_n = 7,
  x_data_range = NULL,
  y_data_range = NULL,
  x_bw = NULL,
  y_bw = NULL,
  granularity = 512
)

Arguments

data

Data frame containing columns x, y, and weight. For a simple random sample, set weight to be constant.

slice_n

Integer number of vertical slices (conditional densities of y given x) to be plotted. Default is 5.

x_data_range

Numeric vector of length 2 containing the range of horizontal values to be plotted. Defaults to the range of the predictor variable in data. You may want to specify a narrower range if the predictor is extremely skewed. Quantile curves and densities will be estimated only on data in this range, and the plot will note the percent truncated.

y_data_range

Numeric vector of length 2 containing the range of vertical values to be plotted. Defaults to the range of the outcome variable in data. You may want to specify a narrower range if the outcome is extremely skewed. Densities are truncated to this range. All data contribute to quantile curve estimation regardless of y_data_range to avoid selection on the outcome, though the visualization is truncated to y_data_range. The plot will note the percent truncated.

x_bw

Numeric bandwidth for density estimation in the x dimension. The standard deviation of a Gaussian kernel. If NULL, this is set by the defaults in stats::density().

y_bw

Numeric bandwidth for density estimation in the y dimension. The standard deviation of a Gaussian kernel. If NULL, this is set by the defaults in stats::density().

granularity

Integer number of points at which to evaluate each density. Defaults to 512, as in stats::density(). Higher values yield more granular density estimates.

Value

List containing marginal and conditional, each of which is a data frame with density estimates.

References

Lundberg, Ian, Robin C. Lee, and Brandon M. Stewart. 2021. "The quantile plot: A visualization for bivariate population relationships." Working paper.

Lundberg, Ian, and Brandon M. Stewart. 2020. "Comment: Summarizing income mobility with multiple smooth quantiles instead of parameterized means." Sociological Methodology 50(1):96-111.

Fasiolo, Matteo, Simon N. Wood, Margaux Zaffran, Raphaƫl Nedellec, and Yannig Goude. 2020. "Fast calibrated additive quantile regression." Journal of the American Statistical Association.


ilundberg/quantileplot documentation built on May 23, 2022, 3:12 a.m.