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 class '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, ...)

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).

Value

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

Examples

library("betareg")

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))
)
                                      q_0.25   q_0.5  q_0.75
1  0.09997 -2.1976   77.56 1.145e-03 0.07549 0.09653 0.12074
2  0.18658 -1.4724  215.06 7.024e-04 0.16816 0.18561 0.20394
3  0.32143 -0.7472  596.36 3.651e-04 0.30842 0.32123 0.33422
4  0.47379 -0.1049 1471.75 1.693e-04 0.46500 0.47378 0.48256
5  0.08568 -2.3676   93.73 8.269e-04 0.06490 0.08273 0.10328
6  0.14212 -1.7978  208.89 5.809e-04 0.12525 0.14097 0.15774
7  0.26285 -1.0312  614.00 3.151e-04 0.25073 0.26259 0.27469
8  0.10324 -2.1617   85.88 1.066e-03 0.07972 0.10017 0.12344
9  0.17652 -1.5401  205.86 7.027e-04 0.15806 0.17547 0.19384
10 0.30245 -0.8357  554.46 3.798e-04 0.28916 0.30221 0.31547
11 0.07881 -2.4587  120.07 5.996e-04 0.06119 0.07647 0.09390
12 0.14365 -1.7853  309.57 3.961e-04 0.12981 0.14288 0.15665
13 0.24751 -1.1120  798.12 2.331e-04 0.23709 0.24730 0.25769
14 0.34394 -0.6458 1537.51 1.467e-04 0.33573 0.34387 0.35208
15 0.16957 -1.5887  342.81 4.096e-04 0.15556 0.16892 0.18287
16 0.27545 -0.9671  821.72 2.426e-04 0.26484 0.27527 0.28586
17 0.33691 -0.6771 1235.66 1.806e-04 0.32780 0.33683 0.34594
18 0.10548 -2.1378  191.40 4.904e-04 0.08984 0.10410 0.11962
19 0.23606 -1.1744  742.04 2.427e-04 0.22542 0.23583 0.24645
20 0.32316 -0.7393 1368.34 1.597e-04 0.31459 0.32308 0.33164
21 0.05383 -2.8665  120.07 4.207e-04 0.03893 0.05137 0.06608
22 0.07928 -2.4521  215.06 3.379e-04 0.06624 0.07798 0.09091
23 0.16906 -1.5923  720.73 1.946e-04 0.15949 0.16876 0.17831
24 0.27063 -0.9914 1677.97 1.176e-04 0.26326 0.27054 0.27789
25 0.08270 -2.4062  248.80 3.037e-04 0.07039 0.08158 0.09380
26 0.17116 -1.5774  798.12 1.775e-04 0.16202 0.17088 0.18000
27 0.31885 -0.7590 2523.27 8.604e-05 0.31257 0.31881 0.32509
28 0.12701 -1.9276  650.84 1.701e-04 0.11801 0.12663 0.13560
29 0.23661 -1.1714 1885.42 9.575e-05 0.22995 0.23651 0.24316
30 0.10508 -2.1420  798.12 1.177e-04 0.09759 0.10475 0.11221
31 0.11952 -1.9970  978.71 1.074e-04 0.11239 0.11926 0.12637
32 0.18402 -1.4894 1998.57 7.509e-05 0.17811 0.18391 0.18980
## 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)
        1         5        10 
5.407e-01 7.165e-01 6.053e-40 
## CDF at each combination of 0.1/0.2 and observations
predict(gy2, newdata = gyd, type = "probability", at = c(0.1, 0.2))
       p_0.1     p_0.2
1  5.407e-01 9.933e-01
5  7.165e-01 9.991e-01
10 6.053e-40 5.828e-09
## 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))
     1      5     10 
0.5407 0.9991 0.4549 
predict(gy2, newdata = gyd, type = "probability", at = c(0.1, 0.2, 0.3), elementwise = TRUE)
     1      5     10 
0.5407 0.9991 0.4549 
## 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)
       p_0.1     p_0.2  p_0.3
1  5.407e-01 9.933e-01 1.0000
5  7.165e-01 9.991e-01 1.0000
10 6.053e-40 5.828e-09 0.4549