Author

Public Health Ontario

Public Health Ontario, Interactive Opioid Tool

Opioid-related morbidity and mortality in Ontario

library(data.table)
library(forecast) #autoplot
Ontario <- fread("Cases of opioid-related morbidity and mortality, Ontario, 2003 - 01 – 2018 - 09.csv")
Toronto_Public_Health <- fread("Cases of opioid-related morbidity and mortality, Toronto Public Health, 2003 - 01 – 2018 - 09.csv")
str(Toronto_Public_Health)
Classes ‘data.table’ and 'data.frame':  189 obs. of  8 variables:
 $ Year - Month             : chr  "2003 - 01" "2003 - 02" "2003 - 03" "2003 - 04" ...
 $ Population               : int  2600854 2600228 2599602 2598977 2598351 2597725 2597099 2596801 2596503 2596205 ...
 $ Rate of ED visits        : num  1 0.5 0.8 0.8 1.1 0.8 1.1 0.9 1.2 1 ...
 $ Count of ED visits       : int  25 13 22 22 28 20 28 24 30 27 ...
 $ Rate of Hospitalizations : num  0.6 0.3 0.5 0.6 0.6 0.5 0.5 0.7 0.4 0.6 ...
 $ Count of Hospitalizations: int  15 9 12 15 15 14 12 18 11 16 ...
 $ Rate of Deaths           : chr  "NA" "NA" "NA" "NA" ...
 $ Count of Deaths          : chr  "NA" "NA" "NA" "NA" ...
 - attr(*, ".internal.selfref")=<externalptr> 
Toronto_Central_LHIN <- fread("Cases of opioid-related morbidity and mortality, Toronto Central LHIN, 2003 - 01 – 2018 - 09.csv")

Trend and Seasonality Decomposition

Ontario_Count_ED_visits.ts <- ts(Ontario$`Count of ED visits`, start = 2003, frequency = 12)
Toronto_Public_Health_Count_ED_visits.ts <- ts(Toronto_Public_Health$`Count of ED visits`, start = 2003, frequency = 12)
Toronto_Central_LHIN_Count_ED_visits.ts <- ts(Toronto_Central_LHIN$`Count of ED visits`, start = 2003, frequency = 12)
Ontario_Count_ED_visits.ts.components <- decompose(Ontario_Count_ED_visits.ts)
Toronto_Public_Health_Count_ED_visits.ts.components <- decompose(Toronto_Public_Health_Count_ED_visits.ts)
plot(Ontario_Count_ED_visits.ts.components)

plot(Toronto_Public_Health_Count_ED_visits.ts.components)

Toronto_Central_LHIN_Count_ED_visits.ts.components <- decompose(Toronto_Central_LHIN_Count_ED_visits.ts)
plot(Toronto_Central_LHIN_Count_ED_visits.ts.components)

SARIMA models and forecasts

D=1 forces seasonality

Toronto_Public_Health_Count_ED_visits.ts.arima <- auto.arima(Toronto_Public_Health_Count_ED_visits.ts, D=1)

Toronto_Public_Health_Count_ED_visits.ts.arima
Series: Toronto_Public_Health_Count_ED_visits.ts 
ARIMA(3,1,1)(1,1,1)[12] 

Coefficients:
         ar1     ar2      ar3      ma1     sar1     sma1
      0.7587  0.0642  -0.2713  -0.7898  -0.2953  -0.6304
s.e.  0.1014  0.0939   0.0771   0.0834   0.1300   0.1191

sigma^2 estimated as 177.3:  log likelihood=-708.23
AIC=1430.46   AICc=1431.13   BIC=1452.65
Toronto_Public_Health_Count_ED_visits.ts.arima.forecast <- forecast(Toronto_Public_Health_Count_ED_visits.ts.arima, level = c(95), h = 24)

autoplot(Toronto_Public_Health_Count_ED_visits.ts.arima.forecast, main = "Monthly Emergency Department (ED) Visits")

Toronto_Public_Health_Rate_of_ED_visits.ts <- ts(Toronto_Public_Health$`Rate of ED visits`, start = 2003, frequency = 12)
Toronto_Public_Health_Rate_of_ED_visits.ts.components <- decompose(Toronto_Public_Health_Rate_of_ED_visits.ts)

plot(Toronto_Public_Health_Rate_of_ED_visits.ts.components)

Toronto_Public_Health_Rate_of_ED_visits.ts.arima <- auto.arima(Toronto_Public_Health_Rate_of_ED_visits.ts, D=1)

Toronto_Public_Health_Rate_of_ED_visits.ts.arima
Series: Toronto_Public_Health_Rate_of_ED_visits.ts 
ARIMA(0,1,0)(1,1,1)[12] 

Coefficients:
         sar1     sma1
      -0.2606  -0.6268
s.e.   0.1348   0.1218

sigma^2 estimated as 0.2475:  log likelihood=-131.09
AIC=268.18   AICc=268.32   BIC=277.7
Toronto_Public_Health_Rate_of_ED_visits.ts.arima.forecast <- forecast(Toronto_Public_Health_Rate_of_ED_visits.ts.arima, level = c(95), h = 24)

autoplot(Toronto_Public_Health_Rate_of_ED_visits.ts.arima.forecast, main = "Monthly Emergency Department (ED) Visits")

Ontario_Count_ED_visits.ts.arima <- auto.arima(Ontario_Count_ED_visits.ts, D=1)

Ontario_Count_ED_visits.ts.arima
Series: Ontario_Count_ED_visits.ts 
ARIMA(0,1,0)(0,1,2)[12] 

Coefficients:
         sma1    sma2
      -0.8092  0.1603
s.e.   0.0885  0.0816

sigma^2 estimated as 1473:  log likelihood=-894.99
AIC=1795.98   AICc=1796.12   BIC=1805.49
Ontario_Count_ED_visits.ts.arima.forecast <- forecast(Ontario_Count_ED_visits.ts.arima, level = c(95), h = 24)

autoplot(Ontario_Count_ED_visits.ts.arima.forecast, main = "Monthly Emergency Department (ED) Visits")

LS0tDQp0aXRsZTogIlRvcm9udG8gYW5kIE9udGFyaW8gT3Bpb2lkIE1vcmJpZGl0eSBUaW1lc2VyaWVzIg0Kb3V0cHV0OiBodG1sX25vdGVib29rDQotLS0NCg0KIyBBdXRob3INCg0KKiBKb3JkYW4gQmVsbA0KKiBKdWx5IDExLCAyMDE5DQoqIDxodHRwczovL2pvcmRhbmJlbGwyMzU3LmdpdGh1Yi5pby9PcGlvaWRfVGltZXNlcmllcy5uYi5odG1sPg0KDQojIFB1YmxpYyBIZWFsdGggT250YXJpbw0KDQpQdWJsaWMgSGVhbHRoIE9udGFyaW8sIFtJbnRlcmFjdGl2ZSBPcGlvaWQgVG9vbF0oaHR0cHM6Ly93d3cucHVibGljaGVhbHRob250YXJpby5jYS9lbi9kYXRhLWFuZC1hbmFseXNpcy9zdWJzdGFuY2UtdXNlL2ludGVyYWN0aXZlLW9waW9pZC10b29sIy9hZ2VTZXgpDQoNCk9waW9pZC1yZWxhdGVkIG1vcmJpZGl0eSBhbmQgbW9ydGFsaXR5IGluIE9udGFyaW8NCg0KYGBge3J9DQpsaWJyYXJ5KGRhdGEudGFibGUpDQpsaWJyYXJ5KGZvcmVjYXN0KSAjYXV0b3Bsb3QNCmBgYA0KDQpgYGB7c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