monotonic | R Documentation |
monotonic()
returns modified values of input vector y
that are smoothed, monotonic, and consistent across all values of input x
. It was designed to be used post-fusion when one wants to ensure a plausible relationship between consumption (x
) and expenditure (y
), under the assumption that all consumers face an identical, monotonic pricing structure. By default, the mean of the returned values is forced to equal the original mean of y
(preserve = TRUE
). The direction of monotonicity (increasing or decreasing) is detected automatically, so use cases are not limited to consumption and expenditure variables.
monotonic(
x,
y,
w = NULL,
preserve = TRUE,
expend = TRUE,
fast = TRUE,
nmax = 5000,
plot = FALSE
)
x |
Numeric. |
y |
Numeric. |
w |
Numeric. Optional observation weights. |
preserve |
Logical. Preserve the original mean of the |
expend |
Logical. Assume |
fast |
Logical. If |
nmax |
Integer. Maximum number of observations to use for smoothing. Set lower for faster computation. |
plot |
Logical. Plot the (sampled) data points and derived monotonic relationship? |
The initial smoothing is accomplished via supsmu
with the result coerced to monotone. If fast = FALSE
and the coercion step modifies the values too much, a second smooth is attempted via a scam
model with either a monotone increasing or decreasing constraint. If the SCAM fails to fit, the function falls back to lm
with simple linear predictions. If y = 0
when x = 0
(as typical for consumption-expenditure variables), then that outcome is enforced in the result. The input data are randomly sampled to no more than nmax
observations, if necessary, for speed.
A numeric vector of modified y
values. Optionally, a plot showing the returned monotonic relationship.
y <- monotonic(x = recs$propane_btu, y = recs$propane_expend, plot = TRUE)
mean(recs$propane_expend)
mean(y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.