Rates using Grouped froecasting with fable

249 Views Asked by At

As I am pretty new to fable for R, I was wondering if it is also possible to forecast a rate instead of counts within a grouped time series.

Here is a short example of the tsibble I created:

   head(data)
   # A tsibble: 6 x 5 [1Y]
   # Key:       sex, age [1]
   year sex   age   counts      pop
  <dbl> <chr> <chr>  <dbl>    <dbl>
1  2005 m     <50     1294 25986547
2  2006 m     <50     1417 26261652
3  2007 m     <50     1690 25712000
4  2008 m     <50     1827 25385000
5  2009 m     <50     1973 25037000
6  2010 m     <50     2076 24678000

as you can see there are two groups: sex(m/f) and agecategories(<50, 50-55,55-60,...). pop stands for population and counts is the number of a certain event per year (2005-2018).

I added an incidence column by

data%>%mutate(incidence=(counts/pop))

Now I would like to fit an arima model for incidence:

# Fit model 
+     model(arima = ARIMA(incidene)) %>%
+     # reconcile
+     mutate(mint = min_trace(incidence)) %>%
+     # forecasts
+     forecast(h = 10)

However, I don't know how to get the incidence-forecast for the top series group? For count data I would use:

# create aggregates
+     aggregate_key(sex * age, value = (sum(counts))

but this just includes a sum of counts which is not applicable for incidence rates...

Maybe someone could help me out?

Thanks in advance!

1

There are 1 best solutions below

2
Mitchell O'Hara-Wild On

You're on the right track with aggregate_key(), which is the first step of hierarchical reconciliation with fable. You can use aggregate_key() to compute aggregations of counts = sum(counts) and pop = sum(pop), and then compute the incidence = counts / pop using mutate().

Edit: However as ratios are not preserved in aggregation, the ratio itself cannot easily be reconciled.