rstanarm::posterior_predict() creates objects of class "ppd" "matrix" "array". I want to convert such objects to clean tibbles. I tried:
library(tidyverse)
library(rstanarm)
#> Loading required package: Rcpp
#> This is rstanarm version 2.21.1
#> - See https://mc-stan.org/rstanarm/articles/priors for changes to default priors!
#> - Default priors may change, so it's safest to specify priors, even if equivalent to the defaults.
#> - For execution on a local, multicore CPU with excess RAM we recommend calling
#> options(mc.cores = parallel::detectCores())
obj <- stan_glm(data = women, height ~ 1, refresh = 0)
pp <- posterior_predict(obj)
pp %>%
as_tibble()
#> # A tibble: 4,000 x 15
#> `1` `2` `3` `4` `5` `6` `7` `8` `9` `10` `11` `12` `13`
#> <ppd> <ppd> <ppd> <ppd> <ppd> <ppd> <ppd> <ppd> <ppd> <ppd> <ppd> <ppd> <ppd>
#> 1 61.1… 61.3… 58.1… 64.7… 59.4… 63.4… 63.9… 64.3… 68.9… 61.3… 65.7… 65.5… 65.5…
#> 2 68.2… 66.8… 68.5… 67.5… 66.9… 67.4… 67.4… 60.5… 62.8… 65.6… 70.8… 64.3… 63.7…
#> 3 66.3… 64.2… 73.2… 68.7… 60.6… 60.7… 64.3… 70.8… 65.0… 68.7… 65.0… 65.2… 60.2…
#> 4 65.4… 61.9… 64.6… 71.1… 59.6… 60.6… 63.0… 57.5… 69.2… 64.5… 63.7… 64.5… 57.0…
#> 5 62.8… 63.1… 59.8… 60.5… 67.8… 60.0… 52.1… 72.1… 66.8… 62.3… 58.0… 68.0… 67.4…
#> 6 70.8… 61.4… 57.8… 69.6… 63.1… 55.9… 67.5… 67.6… 73.8… 57.6… 60.4… 74.6… 64.6…
#> 7 61.7… 61.5… 69.3… 67.7… 70.8… 63.2… 63.5… 65.6… 64.4… 71.6… 67.9… 70.8… 68.2…
#> 8 66.6… 62.0… 74.1… 70.4… 63.9… 58.8… 58.5… 62.5… 70.0… 57.5… 53.4… 62.4… 54.5…
#> 9 67.4… 61.6… 62.7… 69.0… 64.0… 65.4… 62.3… 69.8… 72.0… 61.5… 67.1… 76.0… 70.4…
#> 10 71.6… 65.1… 72.7… 68.9… 57.5… 63.9… 64.9… 65.4… 63.5… 55.1… 71.9… 67.1… 65.7…
#> # … with 3,990 more rows, and 2 more variables: `14` <ppd>, `15` <ppd>
Created on 2020-10-16 by the reprex package (v0.3.0)
I would like each column to be a dbl, as we would get if pp were a simple matrix. But, as you can see, each column is, itself, an object of class ppd. How can I convert an object of class "ppd" "matrix" "array" to a tibble with simple numeric columns?
One solution:
Created on 2020-10-29 by the reprex package (v0.3.0)
Surely there is an easier way . . .