Learn R Programming

distributions3 (version 0.2.2)

vec_proxy.distribution: 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, ...)

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.

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.

Examples

Run this code
 if(!requireNamespace("tibble")) {
  if(interactive() || is.na(Sys.getenv("_R_CHECK_PACKAGE_NAME_", NA))) {
    stop("not all packages required for the example are installed")
  } else q() }

## 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

Run the code above in your browser using DataLab