| add_probs.glm {ciTools} | R Documentation | 
Response Probabilities for Generalized Linear Models
Description
This is the method add_probs uses if the model fit is an
object of class glm. Probabilities are determined through
simulation, using the same method as add_pi.glm. Currently,
only logistic, Poisson, Quasipoisson, and Gamma models are
supported.
Usage
## S3 method for class 'glm'
add_probs(
  df,
  fit,
  q,
  name = NULL,
  yhatName = "pred",
  comparison = "<",
  nSims = 2000,
  ...
)
Arguments
| df | A data frame of new data. | 
| fit | An object of class  | 
| q | A double. A quantile of the response distribution. | 
| name | 
 | 
| yhatName | A string. Name of the vector of predictions. | 
| comparison | A character vector of length one. If
 | 
| nSims | A positive integer. Controls the number of simulated draws to make if the model is Poisson. | 
| ... | Additional arguments. | 
Details
Any of the five comparisons may be made for a Poisson,
quasipoisson, or Gamma model: comparison = "<", ">",
"=", "<=", or ">=". For logistic regression,
the comparison statement must be equivalent to Pr(Y|x = 0) or
Pr(Y|x = 1).
If add_probs is called on a Poisson, quasiPoisson or Gamma
model, a simulation is performed using arm::sim.
If add_probs is called on a logistic model, the fitted
probabilities are used directly (no simulation is required).
If add_probs is called on a Gaussian GLM, the returned
probabilities are identical to those given by
add_probs.lm. In this case, the comparisons < and
<= are identical (likewise for > and >=). If
the comparison = is used in the Gaussian GLM, an informative
error is returned.
Value
A dataframe, df, with predicted values and
probabilities attached.
See Also
add_ci.glm for confidence intervals for
glm objects, add_pi.glm for prediction
intervals of glm objects, and
add_quantile.glm for response quantiles of
glm objects.
Examples
# Fit a Poisson model
fit <- glm(dist ~ speed, data = cars, family = "poisson")
# Determine the probability that a new dist is less than 20, given
# the Poisson model.
add_probs(cars, fit, q = 20)
# Determine the probability that a new dist is greater than 20,
# given the Poisson model.
add_probs(cars, fit, q = 30, comparison = ">")
# Determine the probability that a new dist is greater than or
# equal to 20, given the Poisson model.
add_probs(cars, fit, q = 30, comparison = ">=")
# Fit a logistic model
fit2 <- glm(I(dist > 30) ~ speed, data = cars, family = "binomial")
add_probs(cars, fit2, q = 0, comparison = "=")
add_probs(cars, fit2, q = 1, comparison = "=")