Skip to content

Commit 096c48c

Browse files
Merge pull request #274 from LAMPSPUC/examples
Added quick examples
2 parents ab6b0de + c34b167 commit 096c48c

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,57 @@ Current features include:
5656
* Diagnostics for the residuals of fitted models
5757
* Visualization recipes
5858

59+
## Quick Examples
60+
61+
### Fitting and forecasting
62+
Quick example of different models fit and forecast for the air passengers time-series
63+
64+
```julia
65+
using CSV
66+
using DataFrames
67+
using Plots
68+
using StateSpaceModels
69+
70+
airp = CSV.File(StateSpaceModels.AIR_PASSENGERS) |> DataFrame
71+
log_air_passengers = log.(airp.passengers)
72+
steps_ahead = 30
73+
74+
# SARIMA
75+
model_sarima = SARIMA(log_air_passengers; order = (0, 1, 1), seasonal_order = (0, 1, 1, 12))
76+
fit!(model_sarima)
77+
forec_sarima = forecast(model_sarima, steps_ahead)
78+
79+
# Unobserved Components
80+
model_uc = UnobservedComponents(log_air_passengers; trend = "local linear trend", seasonal = "stochastic 12")
81+
fit!(model_uc)
82+
forec_uc = forecast(model_uc, steps_ahead)
83+
84+
# Exponential Smoothing
85+
model_ets = ExponentialSmoothing(log_air_passengers; trend = true, seasonal = 12)
86+
fit!(model_ets)
87+
forec_ets = forecast(model_ets, steps_ahead)
88+
89+
# Naive model
90+
model_naive = SeasonalNaive(log_air_passengers, 12)
91+
fit!(model_naive)
92+
forec_naive = forecast(model_naive, steps_ahead)
93+
94+
plt_sarima = plot(model_sarima, forec_sarima; title = "SARIMA", label = "");
95+
plt_uc = plot(model_uc, forec_uc; title = "Unobserved components", label = "");
96+
plt_ets = plot(model_ets, forec_ets; title = "Exponential smoothing", label = "");
97+
plt_naive = plot(model_ets, forec_naive; title = "Seasonal Naive", label = "");
98+
99+
plot(plt_sarima, plt_uc, plt_ets, plt_naive; layout = (2, 2), size = (500, 500))
100+
```
101+
![quick_example_airp](./docs/assets/quick_example_airp.png)
102+
103+
### Automatic forecasting
104+
Quick examples on automatic forecasting. When performing automatic forecasting
105+
users should provide the seasonal period if there is one.
106+
```julia
107+
model = auto_ets(log_air_passengers; seasonal = 12)
108+
```
109+
59110
## Contributing
60111

61112
* PRs such as adding new models and fixing bugs are very welcome!

docs/assets/quick_example_airp.png

66.9 KB
Loading

docs/make.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ makedocs(;
2020
],
2121
)
2222

23-
deploydocs(repo="github.com/LAMPSPUC/StateSpaceModels.jl.git")
23+
deploydocs(
24+
repo="github.com/LAMPSPUC/StateSpaceModels.jl.git",
25+
push_preview = true
26+
)

0 commit comments

Comments
 (0)