Learn R Programming

betareg (version 3.2-1)

predict.betareg: Prediction Method for betareg Objects

Description

Extract various types of predictions from beta regression models: First, GLM-style predictions on the scale of responses in (0, 1) or the scale of the linear predictor are provided. Second, various quantities based on the predicted beta distributions are available, e.g., moments, quantiles, probabilities, densities, etc.

Usage

# S3 method for betareg
predict(object, newdata = NULL,
  type = c("response", "link", "precision", "variance", "parameters",
    "distribution", "density", "probability", "quantile"),
  na.action = na.pass, at = 0.5, elementwise = NULL, ...)

Value

Either a vector or matrix of predictions with the same number of observations as rows in newdata.

Arguments

object

fitted model object of class "betareg".

newdata

optionally, a data frame in which to look for variables with which to predict. If omitted, the original observations are used.

type

character indicating type of predictions: fitted means of the response (default, "response" or equivalently "mean"), corresponding linear predictor ("link"), fitted precision parameter phi ("precision"), fitted variances of the response ("variance"), all "parameters" of the response distribution, or the corresponding "distribution" object (using the infrastructure from distributions3). Finally, standard functions for the distribution can be evaluated (at argument at, see below), namely the "density" (or equivalently "pdf"), the "quantile" function, or the cumulative "probability" (or equivalently "cdf").

na.action

function determining what should be done with missing values in newdata. The default is to predict NA.

at

numeric vector at which the predictions should be evaluated if type specifies a function that takes an additional argument.

elementwise

logical. Should each element of the distribution only be evaluated at the corresponding element of at (elementwise = TRUE) or at all elements in at (elementwise = FALSE). Elementwise evaluation is only possible if the number of observations is the same as the length of at and in that case a vector of the same length is returned. Otherwise a matrix is returned. The default is to use elementwise = TRUE if possible, and otherwise elementwise = FALSE.

...

further arguments when type specifies a function, e.g., type = "density" with log = TRUE computes log-densities (or log-likelihoods).

Details

Each prediction for a betareg model internally first computes the parameters for all observations in newdata (or the original data if newdata is missing). These parameters correspond to a predicted beta distribution (or extended-support beta distribution) for each observation. Then the actual predictions can also be moments of the distributions or standard quantities such as densities, cumulative probabilities, or quantiles. The latter are computed with the d/p/q functions such as dbetar (or dxbetax or dxbeta).

Examples

Run this code
options(digits = 4)

data("GasolineYield", package = "betareg")

gy2 <- betareg(yield ~ batch + temp | temp, data = GasolineYield)

cbind(
  predict(gy2, type = "response"),
  predict(gy2, type = "link"),
  predict(gy2, type = "precision"),
  predict(gy2, type = "variance"),
  predict(gy2, type = "quantile", at = c(0.25, 0.5, 0.75))
)

## evaluate cumulative _p_robabilities for (small) new data set
gyd <- GasolineYield[c(1, 5, 10), ]

## CDF at 0.1 for each observation
predict(gy2, newdata = gyd, type = "probability", at = 0.1)

## CDF at each combination of 0.1/0.2 and observations
predict(gy2, newdata = gyd, type = "probability", at = c(0.1, 0.2))

## CDF at elementwise combinations of 0.1/0.2/0.3 and observations
predict(gy2, newdata = gyd, type = "probability", at = c(0.1, 0.2, 0.3))
predict(gy2, newdata = gyd, type = "probability", at = c(0.1, 0.2, 0.3), elementwise = TRUE)

## CDF at all combinations of 0.1/0.2/0.3 and observations
predict(gy2, newdata = gyd, type = "probability", at = c(0.1, 0.2, 0.3), elementwise = FALSE)

Run the code above in your browser using DataLab