Description Usage Arguments Details Value See Also Examples
View source: R/add_probs_glm.R
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.
1 2 3 4 5 6 7 8 9 10 11 |
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. |
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.
A dataframe, df
, with predicted values and
probabilities attached.
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # 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 = "=")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.