The {distributional}
package (used to provide these distribution objects) has since been updated with functions to obtain the shape and parameters of a distribution. These functions are recommended instead of unclassing the distributions, as the internal representation of these distributions may change in the future.
For example, take a Normal distribution:
library(distributional)
fc <- dist_normal(10, 3)
Obtain the parameters from the distribution
parameters(fc)
#> mu sigma
#> 1 10 3
Obtain the shape of the distribution
family(fc)
#> [1] "normal"
For your example…
library(fable)
#> Loading required package: fabletools
beer_fc <- tsibbledata::aus_production %>%
model(ets = ETS(log(Beer) ~ error("M") + trend("Ad") + season("A"))) %>%
forecast(h = "3 years", bootstrap=TRUE, times = 5)
You could extract the parameters and family
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
beer_fc %>%
mutate(parameters(Beer), family(Beer))
#> # A fable: 12 x 6 [1Q]
#> # Key: .model [1]
#> .model Quarter Beer .mean x `family(Beer)`
#> <chr> <qtr> <dist> <dbl> <list> <chr>
#> 1 ets 2010 Q3 sample[5] 411. <dbl [5]> sample
#> 2 ets 2010 Q4 sample[5] 486. <dbl [5]> sample
#> 3 ets 2011 Q1 sample[5] 426. <dbl [5]> sample
#> 4 ets 2011 Q2 sample[5] 382. <dbl [5]> sample
#> 5 ets 2011 Q3 sample[5] 409. <dbl [5]> sample
#> 6 ets 2011 Q4 sample[5] 487. <dbl [5]> sample
#> 7 ets 2012 Q1 sample[5] 424. <dbl [5]> sample
#> 8 ets 2012 Q2 sample[5] 390. <dbl [5]> sample
#> 9 ets 2012 Q3 sample[5] 407. <dbl [5]> sample
#> 10 ets 2012 Q4 sample[5] 483. <dbl [5]> sample
#> 11 ets 2013 Q1 sample[5] 425. <dbl [5]> sample
#> 12 ets 2013 Q2 sample[5] 390. <dbl [5]> sample
Now the x
variable contains a simple list of numbers that you can use unnest()
or other functions to work with.
Created on 2022-11-15 by the reprex package (v2.0.1)