vec_proxy.distribution: Methods for including distributions as vctrs in tibbles

View source: R/tibble-vctrs.R

vec_proxy.distributionR Documentation

Methods for including distributions as vctrs in tibbles

Description

Methods for vec_proxy and vec_restore from vctrs in order to include distribution objects in tibble objects.

Usage

vec_proxy.distribution(x, ...)

vec_restore.distribution(x, to, ...)

Arguments

x, to

Objects inheriting from distribution.

...

Currently not used.

Details

The methods for vec_proxy and vec_restore from vctrs are needed so that distribution objects can be included as a vector column in (and extracted from) tibble data frames. vec_proxy simply adds the class data.frame which is the actual underlying data structure used by distribution objects. This way the number of rows etc. can be correctly determined. Conversely, vec_restore strips off the additional data.frame class and restores the original distribution classes. Users typically do not need to call vec_proxy and vec_restore directly.

Value

The vec_proxy method returns a distribution object which additionally inherits of data.frame while the vec_restore method restores the original distribution classes.

Examples


## Poisson GLM for FIFA 2018 goals data
data("FIFA2018", package = "distributions3")
m <- glm(goals ~ difference, data = FIFA2018, family = poisson)

## Predict fitted Poisson distributions for teams with ability differences
## of -1, 0, 1 (out-of-sample) using the new data as a data.frame
nd <- data.frame(difference = -1:1)
nd$dist <- prodist(m, newdata = nd)
nd

## Do the same using the new data as a tibble
library("tibble")
nt <- tibble(difference = -1:1)
nt$dist <- prodist(m, newdata = nt)
nt


distributions3 documentation built on Sept. 30, 2024, 9:37 a.m.