Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions docs/src/man/examples/airpassengers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ default(size=(800,500))
# Air Passengers (Seasonality)

## Introduction
In this example we will predict the monthly totals in thounsads of international airline passengers with data from 1949 to 1960.
In this example we will predict the monthly totals in thousands of international airline passengers with data from 1949 to 1960.

```@example examples
plot(air()) #hide
```
## Descriptive Analysis & Transformations

### Heteroskedasticity
A cople of obvious feature in the plot of the data is that it shows an non-stationary heteroskedastic time series. However, to facilitate the fitting of an AR model we want a Stationary Homoskedastic time series. With that goal in mind we could consider first a boxcox transformation to deal with the heteroskedasticity but in this case a simple log transformation works just fine.
A couple of obvious feature in the plot of the data is that it shows an non-stationary heteroskedastic time series. However, to facilitate the fitting of an AR model we want a Stationary Homoskedastic time series. With that goal in mind we could consider first a boxcox transformation to deal with the heteroskedasticity but in this case a simple log transformation works just fine.

```@example examples
log_ap = air()
Expand All @@ -26,31 +26,31 @@ plot(log_ap) #hide
```

### Stationary Behavior
We still have a clear non-stationary time series displaying a marked trend and montnly seasonality.
We still have a clear non-stationary time series displaying a marked trend and monthly seasonality.
```@example examples
stl_ap = stl(log_ap.LogPassengers,12,robust=true)
plot(stl_ap)
```
To faciliate the fitting of an AR model we want an stationary time series, and in order to have one we will be using a differentation of order 12 for the trend and seasonality.
To facilitate the fitting of an AR model we want an stationary time series, and in order to have one we will be using a differentiation of order 12 for the trend and seasonality.
```@example examples
d12_log_ap = d(log_ap,1,12)
plot(d12_log_ap) # hide
```
There is a case for second differentation of oder one since it furthers reduces the variance of the resulting time series indicating a potential remaining trend, however this potential improvement might not be enough to justify this new transformation since the existing one offers now a good enough stationary time series to consider an AR model with a constant coefficient.
There is a case for second differentiation of oder one since it furthers reduces the variance of the resulting time series indicating a potential remaining trend, however this potential improvement might not be enough to justify this new transformation since the existing one offers now a good enough stationary time series to consider an AR model with a constant coefficient.

### Evaluating Seasonal Differentation
### Evaluating Seasonal Differentiation

```@example examples
splot(d12_log_ap)
```
After a differentation of order 12 we can also see that the seasonality has mostly disappeared and we can continue our analysis with a reasonalble stationary dataset.
After a differentiation of order 12 we can also see that the seasonality has mostly disappeared and we can continue our analysis with a reasonable stationary dataset.

### Autoregressive Behavior

```@example examples
plot(pacf(d12_log_ap[:,2]))
```
We can see clear auto-correlations with values of the previous two months and with values of the same months in the previous year. Beyond this there seems to be not enough correlation to justify a more complex model, but we can always check this hypothesis lookig at the Information Criteria.
We can see clear auto-correlations with values of the previous two months and with values of the same months in the previous year. Beyond this there seems to be not enough correlation to justify a more complex model, but we can always check this hypothesis looking at the Information Criteria.

## Fitting an AR model

Expand All @@ -61,9 +61,9 @@ ar_tap = ar(d12_log_ap,13)
show(ar_tap) # hide
```
### Fixing Coefficients
As expected we see that ``\Phi1,\Phi2,\Phi12,`` and ``\Phi13`` have highly significant coefficients, also we can see some significance in ``\Phi0``. This confirms the case for a further differentation of order one however, since doing so decreases the normality profile of the residuals we will keep it as it is.
As expected we see that ``\Phi1,\Phi2,\Phi12,`` and ``\Phi13`` have highly significant coefficients, also we can see some significance in ``\Phi0``. This confirms the case for a further differentiation of order one however, since doing so decreases the normality profile of the residuals we will keep it as it is.

Since we want to know the falues of these four parameters without the influcence of the rest we will now fit again the model fixing all coefficients except those five.
Since we want to know the values of these four parameters without the influence of the rest we will now fit again the model fixing all coefficients except those five.

```@example examples
Φ = ar_tap.Φ
Expand Down
8 changes: 4 additions & 4 deletions docs/src/man/examples/london.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ splot(x[:,["Date","Violence"]], title="Seasonal Violent Crimes")
```@example examples
splot(x[:,["Date","Sexual"]], title="Seasonal Sexual Crimes")
```
Sesonality patterns for `MaxTemp` are obvious and noticeable for `Violence`, however there's barely any to be seen in `Sexual`.
Seasonality patterns for `MaxTemp` are obvious and noticeable for `Violence`, however there's barely any to be seen in `Sexual`.

### Normalization
To compare time series with different positive magnitudes and to facilitate an stationary forecasting we will normalize data by dividing each variable by its maximum value.
Expand All @@ -50,7 +50,7 @@ dtx = d(tx,1,12)
plot(dtx)
```

An extra differentation might be required for `Violence` and `Sexual` but this seems to be one to many for `MaxTemp` indicated by an increase in its variance when doing so. Also, the apparent need for a differentation in `Violence` and `Sexual` seems to be a temporary effect rather than a permanent trend or seasonality therefore we will continue with just one differentation of order 12.
An extra differentiation might be required for `Violence` and `Sexual` but this seems to be one to many for `MaxTemp` indicated by an increase in its variance when doing so. Also, the apparent need for a differentiation in `Violence` and `Sexual` seems to be a temporary effect rather than a permanent trend or seasonality therefore we will continue with just one differentiation of order 12.

## Fitting an AR(1) model
Given the scarcity of data for a multivariate model we cannot fit too many parameters while keeping its significance. We will therefore fit an AR of order one.
Expand All @@ -61,11 +61,11 @@ show(xar) # hide
```
The first thing we can do is to use Φ1 to infer directional causality, in this case we see how `MaxTemp` is not influenced at all (with statistical significance) by `Violence` and `Sexual`, which could not possibly be otherwise in this case. On the other hand we have `Violence` and `Sexual` being affected significantly by `MaxTemp`.

The relathionship between `Violence` and `Sexual` is both ways, however, the effect `Sexual` has on `Violence` is small and barely significant which might prompt us to consider to remove it altogether, the opposite though is not true, `Violence` has a strong and significant influence in `Sexual`.
The relationship between `Violence` and `Sexual` is both ways, however, the effect `Sexual` has on `Violence` is small and barely significant which might prompt us to consider to remove it altogether, the opposite though is not true, `Violence` has a strong and significant influence in `Sexual`.


## Fixing Coefficients
Let's now fix to 0 the influcence of `Violence` and `Sexual` on `MaxTemp`, remove the influence from `MaxTemp` on `Sexual` since it is accounted for via `Violence` and the non-significant influence of `Sexual` on `Violence`. If now we fit again the model we have
Let's now fix to 0 the influence of `Violence` and `Sexual` on `MaxTemp`, remove the influence from `MaxTemp` on `Sexual` since it is accounted for via `Violence` and the non-significant influence of `Sexual` on `Violence`. If now we fit again the model we have

```@example examples
dϕ1 = xar.Φ
Expand Down
6 changes: 3 additions & 3 deletions docs/src/man/examples/quakes.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ Data's behavior seems to follow a Normal distribution with no strong indications
```@example examples
plot(pacf(qk.quakes))
```
The partial autoregression function shows us that there seems to be a significant correlation to the number of earthquakes taking place last year. If we were looking for seasonality we could check on periods of 11 or 15 years since they show a nearly significant correlations but since they're most likely spureous (...or are they?) we will ignore them in this analysis.
The partial autoregression function shows us that there seems to be a significant correlation to the number of earthquakes taking place last year. If we were looking for seasonality we could check on periods of 11 or 15 years since they show a nearly significant correlations but since they're most likely spurious (...or are they?) we will ignore them in this analysis.

## Fitting an AR Model
```@example examples
ar_qk = ar(qk)
show(ar_qk) # hide
```
In the AR model of order one we have highly significant coefficients and increasing its order does not provide important changes in the Information Criteria, however, the residuals show a barely significant normality behavior and we may consider to transform our data to improve on that.
Given tha large noise in the model, tranformations to improve results will not be dramatic and therefore we will continue with a simple AR model of order one for our forecasting.
Given the large noise in the model, transformations to improve results will not be dramatic and therefore we will continue with a simple AR model of order one for our forecasting.


## Forecasting Earthquakes
```@example examples
fc_qk = forecast(ar_qk,10);
plot(fc_qk)
```
The plot shows us the forecast for the next ten years and, as we see, the large noise in the model does not allow us to be very accurate in our forecasting, but at least we can confidently say that there is a resonable chance to have a larger number of big earthquakes in 2021 and 2022 than the number we had in 2020.
The plot shows us the forecast for the next ten years and, as we see, the large noise in the model does not allow us to be very accurate in our forecasting, but at least we can confidently say that there is a reasonable chance to have a larger number of big earthquakes in 2021 and 2022 than the number we had in 2020.

```@example examples
show(fc_qk) # hide
Expand Down
2 changes: 1 addition & 1 deletion docs/src/man/examples/whatif.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To answer this questions and similar ones we need a way to instruct our forecast

## London Crime/Weather Scenarios

Let's show how to use the Great London Crime/Weather example. In this example we see how weather temperature affects/explains criminality in Greater London. However, the prediction of temperature is not as accurate as it would be if we use forecast coming from (metoffice)[metoffice.gov.uk] instead those predicted by an AR(1) model. Therefore in order to have more accurate predictions about crime we want to overrule the temperature forecast of the AR(1) model with the forecast comming from `metoffice`.
Let's show how to use the Great London Crime/Weather example. In this example we see how weather temperature affects/explains criminality in Greater London. However, the prediction of temperature is not as accurate as it would be if we use forecast coming from (metoffice)[metoffice.gov.uk] instead those predicted by an AR(1) model. Therefore in order to have more accurate predictions about crime we want to overrule the temperature forecast of the AR(1) model with the forecast coming from `metoffice`.

These metoffice predictions would not be much different than those from the AR(1) model therefore, in order to better visualize impacts in the forecast, we will play with an hypothetical scenario in which temperatures increase one degree per month for two years straight.

Expand Down
6 changes: 3 additions & 3 deletions docs/src/man/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ plot!(x,sma(y,100,true), linewidth = 2, label= "Moving Avg 100", color = :orange
## STL on CO2 dataset

For this example we will be using the co2 data used by the creators of STL to
demostrate its funcitonality, below we can see such time series.
demonstrate its functionality, below we can see such time series.

```@example quickstart
using Plots
Expand All @@ -53,7 +53,7 @@ using Forecast
plot(co2(), legend=:bottomright)
```

The parameters used for STL they're also from the orginal paper, a period of
The parameters used for STL they're also from the original paper, a period of
365 days is used (removing leap years extra day), a robust fit is required and
seasonality post-smoothing is applied.

Expand All @@ -70,7 +70,7 @@ The image below comes from the original paper for comparison purposes.
<img src="../../images/stl.png" width="800px"/>
```

## Cross-Correlation on shifted dasaset
## Cross-Correlation on shifted dataset

Here we cross-correlate two identical series shifted by six positions, the plot
shows how the peak correlation is at position six.
Expand Down
Loading