Convert point forecasts in fable from exponential format to normal numbers

89 views Asked by At

I have created the following tsibble (named afsi)

structure(list(Date = structure(c(12509, 12600, 12692, 12784, 
12874, 12965, 13057, 13149, 13239, 13330, 13422, 13514, 13604, 
13695, 13787, 13879, 13970, 14061, 14153, 14245, 14335, 14426, 
14518, 14610, 14700, 14791, 14883, 14975, 15065, 15156, 15248, 
15340, 15431, 15522, 15614, 15706, 15796, 15887, 15979, 16071, 
16161, 16252, 16344, 16436, 16526, 16617, 16709, 16801, 16892, 
16983, 17075, 17167, 17257, 17348, 17440, 17532, 17622, 17713, 
17805, 17897), fiscal_start = 1, class = c("yearquarter", "vctrs_vctr"
)), Index = c(4.6049904235401, 4.60711076016453, 4.60980084146652, 
4.61025389170935, 4.60544515681515, 4.60889021700954, 4.60983993107244, 
4.61091608826696, 4.61138799159174, 4.61294431148318, 4.61167545843765, 
4.61208284263432, 4.61421991328081, 4.61530485425155, 4.61471465043043, 
4.6155992084451, 4.61195799200607, 4.61178486640435, 4.61037927954796, 
4.60744590947049, 4.59979957741728, 4.59948551500254, 4.60078678080182, 
4.60556092645471, 4.60934962087565, 4.60981147563749, 4.61060477704678, 
4.61158365084251, 4.60963435263623, 4.61018215733317, 4.61209710959768, 
4.61231368335184, 4.61071363571141, 4.61019496497916, 4.60948652606191, 
4.61068813487859, 4.6084092003352, 4.60972706132393, 4.60866915174087, 
4.61192565195909, 4.60878767339377, 4.61341471281265, 4.61015272152397, 
4.6093479714315, 4.60750965935653, 4.60768790690338, 4.60676463096309, 
4.60746490411374, 4.60885670935448, 4.60686846708382, 4.60688947889575, 
4.60867708110485, 4.60448791268212, 4.60387348166032, 4.60569806689426, 
4.6069320880709, 4.6087143894128, 4.61059688801283, 4.61065399116698, 
4.61071421014339)), row.names = c(NA, -60L), key = structure(list(
    .rows = structure(list(1:60), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), row.names = c(NA, -1L), class = c("tbl_df", 
"tbl", "data.frame")), index = structure("Date", ordered = TRUE), index2 = "Date", interval = structure(list(
    year = 0, quarter = 1, month = 0, week = 0, day = 0, hour = 0, 
    minute = 0, second = 0, millisecond = 0, microsecond = 0, 
    nanosecond = 0, unit = 0), .regular = TRUE, class = c("interval", 
"vctrs_rcrd", "vctrs_vctr")), class = c("tbl_ts", "tbl_df", "tbl", 
"data.frame"))

Using this data, I've created an ARIMA model and simulated forecasts from it for a year ahead using the fable package. I noticed that my table produces the forecasts in exponential notation which aren't too great to read, is there a way in which I could convert the point forecasts (under the Index column in my table) to appear as a normal number (and perhaps round to 5 digits)?

library(fable)

fit <- afsi %>%
  model(arima = ARIMA(Index))

table <- fit1 %>% forecast(h='1 year')

the results from table look as follows

# A fable: 4 x 4 [1Q]
# Key:     .model [1]
  .model    Date           Index .mean
  <chr>    <qtr>          <dist> <dbl>
1 arima  2019 Q2 N(4.6, 4.6e-06)  4.61
2 arima  2019 Q3 N(4.6, 7.4e-06)  4.61
3 arima  2019 Q4   N(4.6, 9e-06)  4.61
4 arima  2020 Q1 N(4.6, 9.9e-06)  4.61
1

There are 1 answers

0
akrun On BEST ANSWER

We can set the options

 options(scipen = 999)

-before

table
# A fable: 4 x 4 [1Q]
# Key:     .model [1]
#  .model    Date           Index .mean
#  <chr>    <qtr>          <dist> <dbl>
#1 arima  2019 Q2 N(4.6, 4.6e-06)  4.61
#2 arima  2019 Q3 N(4.6, 7.4e-06)  4.61
#3 arima  2019 Q4   N(4.6, 9e-06)  4.61
#4 arima  2020 Q1 N(4.6, 9.9e-06)  4.61

options(scipen = 999)

-after

table <- fit %>% 
         forecast(h='1 year')
 table
# A fable: 4 x 4 [1Q]
# Key:     .model [1]
#  .model    Date             Index .mean
#  <chr>    <qtr>            <dist> <dbl>
#1 arima  2019 Q2 N(4.6, 0.0000046)  4.61
#2 arima  2019 Q3 N(4.6, 0.0000074)  4.61
#3 arima  2019 Q4  N(4.6, 0.000009)  4.61
#4 arima  2020 Q1 N(4.6, 0.0000099)  4.61