Learn R Programming

ciTools (version 0.1.0)

add_quantile.glm: Quantiles for the Response of a Generalized Linear Model

Description

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 a Poisson regression with the \(\log\)-link function.

Usage

# S3 method for glm
add_quantile(tb, fit, p, name = NULL, yhatName = "pred",
  nSims = 200, ...)

Arguments

tb

A tibble or data frame of new data.

fit

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

p

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

name

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

yhatName

A string. Name of the vector of predictions.

nSims

A positive integer. Set the number of simulated draws to use.

...

Additional arguments.

Value

A tibble, tb, with predicted values and level p quantiles attached.

Details

Quantiles of generalized linear models are determined by add_quantile through a simulation using arm::sim.

See Also

add_ci.lm for confidence intervals for lm objects, add_pi.lm for prediction intervals of lm objects, and add_probs.lm for response probabilities of lm objects.

Examples

Run this code
# NOT RUN {
# 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)

# }

Run the code above in your browser using DataLab