add_quantile.glm {ciTools}R Documentation

Quantiles for the Response of a Generalized Linear Model


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, ...)



A data frame of new data.


An object of class glm. Predictions are made with this object.


A real number between 0 and 1. Sets the probability level of the quantiles.


NULL or a string. If NULL, quantiles automatically will be named by add_quantile, otherwise, they will be named name.


A string. Name of the vector of predictions.


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.

See Also

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.3-quantile (or 30th percentile) of new distances,
# given the Poisson model?
add_quantile(cars, fit, p = 0.3)

# As above, but now find the 0.5-quantile (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)

[Package ciTools version 0.6.1 Index]