stsm_estimate {autostsm} | R Documentation |

Estimates a structural time series model using the Kalman filter and maximum likelihood. The seasonal and cycle components are assumed to be of a trigonometric form. The function checks three trend specifications to decompose a univariate time series into trend, cycle, and/or seasonal components plus noise. The function automatically detects the frequency and checks for a seasonal and cycle component if the user does not specify the frequency or decomposition model. This can be turned off by setting freq or specifying decomp. State space model for decomposition follows Yt = T_t + C_t + S_t + A*X_t + e_t, e_t ~ N(0, sig_e^2) Y is the data T is the trend component C is the cycle component S is the seasonal component X is the exogenous data with parameter vector B e is the observation error

stsm_estimate( y, exo = NULL, freq = NULL, decomp = NULL, trend = NULL, unconstrained = FALSE, saturating_growth = FALSE, multiplicative = NULL, par = NULL, seasons = NULL, cycle = NULL, interpolate = NULL, interpolate_method = NULL, cores = NULL, det_obs = FALSE, det_trend = NULL, det_seas = FALSE, det_drift = FALSE, det_cycle = FALSE, sig_level = 0.01, optim_methods = c("BFGS", "NM", "CG", "SANN"), maxit = 10000, verbose = FALSE )

`y` |
Univariate time series of data values. May also be a 2 column data frame containing a date column. |

`exo` |
Matrix of exogenous variables. Can be used to specify regression effects or other seasonal effects like holidays, etc. |

`freq` |
Frequency of the data (1 (yearly), 4 (quarterly), 12 (monthly), 365.25/7 (weekly), 365.25 (daily)), default is NULL and will be automatically detected |

`decomp` |
Decomposition model ("tend-cycle-seasonal", "trend-seasonal", "trend-cycle", "trend-noise") |

`trend` |
Trend specification ("random-walk", "random-walk-drift", "double-random-walk", "random-walk2"). The default is NULL which will choose the best of all specifications based on the maximum likelihood. "random-walk" is the random walk trend. "random-walk-drift" is the random walk with constant drift trend. "double-random-walk" is the random walk with random walk drift trend. "random-walk2" is a 2nd order random walk trend as in the Hodrick-Prescott filter. If trend is "random-walk", the trend model is T_t = T_t-1 + e_t, e_t ~ N(0, sig_t^2) If trend is "random-walk-drift", the trend model is T_t = T_t-1 + D_t-1 + e_t, e_t ~ N(0, sig_t^2) with D_t = d + phi_d*D_t-1 + n_t, n_t ~ N(0, sig_d^2) If trend is "double-random-walk", the trend model is T_t = M_t-1 + T_t-1 + e_t, e_t ~ N(0, sig_t^2) with M_t = M_t-1 + n_t, n_t ~ N(0, sig_d^2) If trend is "random-walk2", the trend model is T_t = 2T_t-1 - T_t-2 + e_t, e_t ~ N(0, sig_t^2) |

`unconstrained` |
Logical whether to remove inequality constraints on the trend during estimation |

`saturating_growth` |
Force the growth rate to converge to 0 in the long term |

`multiplicative` |
If data should be logged to create a multiplicative model. If multiplicative = TRUE, then the data is logged and the original model becomes multiplicative (Y_t = T_t * C_t * S_t * BX_t * e_t) |

`par` |
Initial parameters, default is NULL |

`seasons` |
The seasonal periods: i.e. c(365.25, 7 if yearly and weekly seasonality). Default is NULL and will be estimated via wavelet analysis. Can set to FALSE if want no seasonality |

`cycle, ` |
The period for the longer-term cycle. Deafult is NULL and will be estimated via wavelet analysis. Can set to FALSE if want no cycle. |

`interpolate` |
Character string giving frequency to interpolate to: i.e. "quarterly", "monthly", "weekly", "daily" |

`interpolate_method` |
Character string giving the interpolation method: i.e. "eop" for end of period, "avg" for period average, or "sum" for period sum. |

`cores` |
Number of cores to use for seasonality and cycle detection |

`det_obs` |
Set the observation equation error variance to 0 (deterministic observation equation) If det_obs = TRUE then the error variance of the observation equation (sig_e) is set to 0 |

`det_trend` |
Set the trend error variance to 0 (deterministic trend) If det_trend = TRUE then the error variance of the trend equation (sig_t) is set to 0 and is referred to as a smooth trend |

`det_seas` |
Set the seasonality error variances to 0 (deterministic seasonality) If det_seas = TRUE then the error variance all seasonality frequency j equations (sig_s) are set to 0 and is referred to as deterministic seasonality |

`det_drift` |
Set the drift error variance to 0 (deterministic drift) If det_drift = TRUE then the error variance of the drift equation (sig_d) is set to 0 and is refereed to as a deterministic drift |

`det_cycle` |
Set the cycle error variance to 0 (deterministic cycle) If det_cycle = TRUE then the error variance of the cycle equation (sig_c) is set to 0 and is referred to as a deterministic cycle |

`sig_level` |
Significance level to determine statistically significant seasonal frequencies |

`optim_methods` |
Vector of 1 to 3 optimization methods in order of preference ("NR", "BFGS", "CG", "BHHH", or "SANN") |

`maxit` |
Maximum number of iterations for the optimization |

`verbose` |
Logical whether to print messages or not |

List of estimation values including a data table with coefficients, convergence code, frequency, decomposition, seasonality, cyclicality, and trend specification as well as the a data table with the original data with dates. Any exogenous data given is also returned.

## Not run: #GDP Not seasonally adjusted library(autostsm) data("NA000334Q", package = "autostsm") #From FRED NA000334Q = data.table(NA000334Q, keep.rownames = TRUE) colnames(NA000334Q) = c("date", "y") NA000334Q[, "date" := as.Date(date)] NA000334Q[, "y" := as.numeric(y)] NA000334Q = NA000334Q[date >= "1990-01-01", ] stsm = stsm_estimate(NA000334Q) ## End(Not run)

[Package *autostsm* version 2.0 Index]