Description Usage Arguments Details Value References Examples
Obtains predictions from a fitted negative binomial 1 model object.
1 2 3 4 |
object |
a fitted object of class inheriting from " |
newdata |
optionally, a data frame in which to look for variables with which to predict. |
type |
the type of prediction required. The default is on the
scale of the linear predictors; |
na.action |
function determining what should be done with missing values in |
at |
quantiles or counts. |
... |
additional arguments to be passed. |
newdata
must contail all columns used in the estimation. If
omitted, the fitted linear predictors are used.
For type = "response"
(as well as type = "location"
), the conditional mean, the inverse link
applied to the linear predictor, is calculated.
type = "probability"
computes the expected probabilities for each count
at = 0, 1, 2, 3, ...
, whereas type = "quantile"
gives the quantile
function for probabilities at
.
Returns a vector of predictions.
Cameron AC & Trivedi PK (1986). Econometric Models Based on Count Data: Comparisons and Applications of Some Estimators and Tests, Journal of Applied Econometrics, 1, 29–53.
Cameron AC & Trivedi PK (2013). “Regression Analysis of Count Data”, Cambridge University Press.
Lawless JF (1987). Negative Binomial and Mixed Poisson Regression, The Canadian Journal of Statistics, 15(3), 209–225.
Winkelmann R & Boes S (2009). “Analysis of Microdata”, Springer, Second Edition.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ## packages
require("Formula")
## data generating process
dgp <- function(n = 1000, coef = c(0.2, 0.3, 0, 2)) {
d <- data.frame(
x1 = runif(n, -1, 1),
x2 = runif(n, -1, 1)
)
d$mu <- exp(coef[1] + coef[2] * d$x1 + coef[3] * d$x2)
d$y <- rnbinom(n, mu = d$mu, size = d$mu / coef[4])
return(d)
}
## simulate data
set.seed(2007-05-15)
d <- dgp()
## model
m1 <- negbin1(y ~ x1 + x2, data = d)
## predictions
newd <- data.frame(x1 = c(2, 0, 1, 4), x2 = c(1, 0, -1, 1))
predict(m1, newd, type = "location")
predict(m1, newd, type = "response")
predict(m1, newd, type = "quantile", at = 0.95)
predict(m1, newd, type = "probability", at = 2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.