add_quantile {ciTools}  R Documentation 
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.
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
Yx
, not E[Yx]
. 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
levelp quantiles attached.
add_ci
for confidence intervals,
add_probs
for response level probabilities, and
add_pi
for prediction intervals
# 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 + (1Subject), 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")