Plot a statistic of y conditioned on the value of x
plot_y_conditioned_on_x.RdFor paired measurements (x,y), plot a specified statistic stat (e.g. the mean) of
y for values of x within bins specified by the vector bins
Usage
plot_y_conditioned_on_x(
x,
y,
bins = NULL,
stat = "median",
bin_by_quantile = T,
n_bins = 10,
error_bar_range = 0.25,
xlab = "",
ylab = "",
main = "",
xlim = NULL,
ylim = NULL
)Arguments
- x
vector of numbers whose value will be conditioned on
- y
vector of numbers from which a statistic will be computed for values associated with each
xbin- bins
bins to use (will override
bin_by_quantileandn_binsif specified)- stat
which statistic of the distribution of
yto use (can be'mean' or 'median')- bin_by_quantile
specifies whether to bin based on quantiles of the overall distribution of
x(TorF)- n_bins
number of bins to create if
bin_by_quantile = T(bins will be evenly spaced according to quantiles)- error_bar_range
if not
NULL, will produce error bars spanning a given quantile range of the distribution ofyfor each bin. should be between0and0.5(defaults to0.25, or interquantile range)- xlab
label for x axis
- ylab
label for y axis
- main
main plot label
- xlim
if specified, sets limits of x axis
- ylim
if specified, sets limits of y axis
Value
Creates a plot, and also outputs a list with bins (bins used), mids (the midpoints
of the x bins), y_stats (the mean or median of y for each bin), y_uppers
and y_lowers (the upper and lower qauntiles of y for each bin as specified
by error_bar_range) and ns (the number of data points in each bin)