Description Usage Arguments Details Value See Also Examples
This is a generic function to append regression quantiles to a data
frame. A regression quantile q is a point such that
Pr(Response | Covariates < q) = p. These quantiles are
generated for the fitted value of each observation in
df
. Quantiles are then appended to df
and returned to
the user as a data frame.
1 | add_quantile(df, fit, p = 0.5, name = NULL, yhatName = "pred", ...)
|
df |
A data frame of new data. |
fit |
An object of class |
p |
A double. A probability that determines the quantile. Must be between 0 and 1. |
name |
|
yhatName |
A string. Name of the vector of predictions. |
... |
Additional arguments |
For more specific information about the arguments that are applicable for each type of model, consult:
add_quantile.lm
for linear regression response quantiles
add_quantile.glm
for generalized linear regression response quantiles
add_quantile.lmerMod
for linear mixed models response quantiles
add_quantile.glmerMod
for generalized linear mixed models response quantiles
add_quantile.survreg
for accelerated failure time response quantiles
Note: Except in add_ci.survreg
, the quantiles that
add_quantile
calculates are on the distribution of
Y|x, not E[Y|x]. That is, they use the same
distribution that determines a prediction interval, not the
distribution that determines a confidence interval.
A dataframe, df
, with predicted values and
level-p quantiles attached.
add_ci
for confidence intervals,
add_probs
for response level probabilities, and
add_pi
for prediction intervals
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # Fit a linear model
fit <- lm(dist ~ speed, data = cars)
# Find the 0.4 quantile (or 40th percentile) of new distances for
# each observations in cars, conditioned on the linear model.
add_quantile(cars, fit, p = 0.4)
# Fit a Poisson model
fit2 <- glm(dist ~ speed, family = "poisson", data = cars)
# Find the 0.4 quantile (or 40th percentile) of new distances for
# each observation in cars, conditioned on the Poisson model.
add_quantile(cars, fit2, p = 0.4)
# Fit a random intercept linear mixed model
fit3 <- lme4::lmer(Reaction ~ Days + (1|Subject), data = lme4::sleepstudy)
# Find the 0.4 quantile (or 40 percentile) of reaction times for
# each observation in the sleepstudy data. Condition on the model and random effects.
add_quantile(lme4::sleepstudy, fit3, p = 0.4, type = "parametric")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.