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 teamsdata("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 defaultpm<-promodel(m)predict(pm, newdata =final)
distribution
127 Poisson(lambda = 1.6044114)
128 Poisson(lambda = 0.9537873)
## all other procast types are available as wellpredict(pm, newdata =final, type ="density", at =0:4)