Predictions and Residuals Dispatch for Probabilistic Models

Description

The function promodel is a wrapper for dispatching the base predict and residuals methods to the procast and proresiduals functions for probabilistic forecasts and probabilistic residuals, respectively.

Usage

promodel(object)

## S3 method for class 'promodel'
residuals(object, ...)

## S3 method for class 'promodel'
predict(object, ...)

Arguments

object a fitted model object for which procast and/or proresiduals work.
further arguments passed on to procast or proresiduals, respectively.

Details

The default methods for procast and proresiduals in this package make a wide range of different probabilistic forecasts and probabilistic residuals available for many fitted model object classes. However, it may sometimes be useful to call these flexible methods via the base predict and residuals methods. For example, this may be useful in combination with other packages that rely on the base functions such as marginaleffects.

Therefore, the promodel wrapper function simply adds an additional class “promodel” (probabilistic model) to the original class of an object. Then the methods for predict and residuals then strip off this class again before calling procast and proresiduals, respectively.

Examples

library("topmodels")

## Poisson regression model for FIFA 2018 data:
## number of goals scored by each team in each game, explained by
## predicted ability difference of the competing teams
data("FIFA2018", package = "distributions3")
m <- glm(goals ~ difference, data = FIFA2018, family = poisson)

## prediction using a new data set (final of the tournament)
final <- tail(FIFA2018, 2)

## base predict method computes linear predictor on link scale (here in logs)
predict(m, newdata = final)
        127         128 
 0.47275699 -0.04731455 
## procast-based method computes distribution object by default
pm <- promodel(m)
predict(pm, newdata = final)
                   distribution
127 Poisson(lambda = 1.6044114)
128 Poisson(lambda = 0.9537873)
## all other procast types are available as well
predict(pm, newdata = final, type = "density", at = 0:4)
          d_0       d_1       d_2        d_3        d_4
127 0.2010078 0.3224993 0.2587107 0.13835949 0.05549639
128 0.3852791 0.3674743 0.1752462 0.05571586 0.01328527
predict(pm, newdata = final, type = "cdf", at = 0:4)
          p_0       p_1       p_2       p_3       p_4
127 0.2010078 0.5235071 0.7822178 0.9205773 0.9760737
128 0.3852791 0.7527534 0.9279995 0.9837154 0.9970007
## the base residuals method defaults to deviance residuals
## but the proresiduals-based method defaults to quantile residuals
head(residuals(m))
          1           2           3           4           5           6 
 1.98287409 -1.31569179 -1.43503752 -0.42419390  1.13746339 -0.06469232 
          1           2           3           4           5           6 
 1.90174348 -2.23225564 -0.95137088 -0.06020531  1.34631576  0.21552074