add_quantile.glm {ciTools}  R Documentation 
This function is one of the methods of
add_quantile
. Currently, you can only use this function to
compute the quantiles of the response of Poisson, Quasipoisson,
Gamma, or Gaussian regression models. Quantile estimates for
Bernoulli response variables (i.e., logistic regression) are not
supported.
## S3 method for class 'glm'
add_quantile(df, fit, p, name = NULL, yhatName = "pred", nSims = 2000, ...)
df 
A data frame of new data. 
fit 
An object of class 
p 
A real number between 0 and 1. Sets the probability level of the quantiles. 
name 

yhatName 
A string. Name of the vector of predictions. 
nSims 
A positive integer. Set the number of simulated draws to use. 
... 
Additional arguments. 
Quantiles of generalized linear models are determined by
add_quantile
through a simulation using arm::sim
. If
a Quasipoisson regression model is fit, simulation using the
Negative Binomial distribution is performed, see Gelman and Hill
(2007).
If add_quantile.glm
is called on a Gaussian GLM with
identity link function, the returned quantiles are identical to
those of add_quantile.lm
. If a different link function is
used, the appropriate inverse transformation is applied.
A dataframe, df
, with predicted values and level
p quantiles attached.
add_ci.glm
for confidence intervals for
glm
objects, add_pi.glm
for prediction
intervals of glm
objects, and add_probs.glm
for response probabilities of glm
objects.
# Fit a Poisson GLM
fit < glm(dist ~ speed, data = cars, family = "poisson")
# What is the 0.3quantile (or 30th percentile) of new distances,
# given the Poisson model?
add_quantile(cars, fit, p = 0.3)
# As above, but now find the 0.5quantile (50th percentile), change
# the number of simulations to run, and give the vector of
# quantiles a custom name.
add_quantile(cars, fit, p = 0.5, name = "my_quantile", nSims = 300)