Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable distribution vectors in tibbles #108

Merged
merged 2 commits into from
Sep 10, 2024
Merged

Enable distribution vectors in tibbles #108

merged 2 commits into from
Sep 10, 2024

Conversation

zeileis
Copy link
Collaborator

@zeileis zeileis commented Sep 10, 2024

Alex @alexpghayes, I recently noticed that we had provided enough S3 methods for distribution objects that they could be included in data.frame objects. However, it was not possible to include them in tibble objects.

Now I was able to work out (with the help of Hannah @hfrick, thanks!) that we only need vec_proxy() and vec_restore() methods in order to use distribution vectors in tibble. The vec_proxy() adds the data.frame class (i.e., the internal data structure underlying distribution objects) and vec_restore() removes it again. For example, you can get predicted distributions in tibbles:

library("distributions3")
library("tibble")
data("FIFA2018", package = "distributions3")
m <- glm(goals ~ difference, data = FIFA2018, family = poisson)
nt <- tibble(difference = -1:1)
nt$dist <- prodist(m, newdata = nt)
nt
## # A tibble: 3 × 2
##   difference dist                    
##        <int> <Poisson>               
## 1         -1 Poisson(lambda = 0.8181)
## 2          0 Poisson(lambda = 1.2370)
## 3          1 Poisson(lambda = 1.8704)

@alexpghayes alexpghayes merged commit 0c1507c into main Sep 10, 2024
11 checks passed
@zeileis zeileis deleted the tibble-vctrs branch September 10, 2024 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants