Title: | State Space Framework and Structural Time Series with 'JDemetra+ 3.x' |
---|---|
Description: | R Interface to 'JDemetra+ 3.x' (<https://github.com/jdemetra>) time series analysis software. It offers access to several functions on state space models and structural time series. |
Authors: | Jean Palate [aut, cre], Tanguy Barthelemy [art] |
Maintainer: | Jean Palate <[email protected]> |
License: | EUPL |
Version: | 2.1.1 |
Built: | 2024-11-10 02:58:57 UTC |
Source: | https://github.com/rjdverse/rjd3sts |
Add a building block to the considered equation
add_equation(equation, item, coeff = 1, fixed = TRUE, loading = NULL)
add_equation(equation, item, coeff = 1, fixed = TRUE, loading = NULL)
equation |
the equation |
item |
the block of the state array that will be linked to the observation corresponding to this equation through the specified loading and coefficient |
coeff |
the value of the coefficient associated to the block of latent variables defined by |
fixed |
logical that triggers estimation of coeff (FALSE) or fixes it (TRUE) to a pre-specified value |
loading |
the loading that links the block to the observation |
Title
aggregation(name, components)
aggregation(name, components)
components |
Functions to create an autoregressive model (ar
) or a
modified autoregressive model (ar2
)
ar( name, ar, fixedar = FALSE, variance = 0.01, fixedvariance = FALSE, nlags = 0, zeroinit = FALSE ) ar2( name, ar, fixedar = FALSE, variance = 0.01, fixedvariance = FALSE, nlags = 0, nfcasts = 0 )
ar( name, ar, fixedar = FALSE, variance = 0.01, fixedvariance = FALSE, nlags = 0, zeroinit = FALSE ) ar2( name, ar, fixedar = FALSE, variance = 0.01, fixedvariance = FALSE, nlags = 0, nfcasts = 0 )
ar |
vector of the AR coefficients ( |
fixedar |
boolean that triggers the estimation of the AR coefficients ( |
variance |
the variance ( |
fixedvariance |
boolean that triggers the estimation of the variance ( |
nlags |
integer specifying how many lags of the state variable are needed |
zeroinit |
boolean determining the initial condition for the state variable,
which is equal to zero if |
nfcasts |
integer specifying how many forecasts of the state variable are needed |
The AR process is defined by
where
is an auto-regressive polynomial.
Autoregressive Integrated Moving Average (ARIMA) Model
arima(name, ar, diff, ma, var = 1, fixed = FALSE)
arima(name, ar, diff, ma, var = 1, fixed = FALSE)
fixed |
Autoregressive Moving Average (ARMA) Model
arma(name, ar, fixedar = FALSE, ma, fixedma = FALSE, var = 1, fixedvar = FALSE)
arma(name, ar, fixedar = FALSE, ma, fixedma = FALSE, var = 1, fixedvar = FALSE)
fixedvar |
Title
cumul(name, core, period, start = 0)
cumul(name, core, period, start = 0)
start |
Title
cycle( name, factor = 0.9, period = 60, fixed = FALSE, variance = 0.01, fixedvariance = FALSE )
cycle( name, factor = 0.9, period = 60, fixed = FALSE, variance = 0.01, fixedvariance = FALSE )
fixedvariance |
Create equation
equation(name, variance = 0, fixed = TRUE)
equation(name, variance = 0, fixed = TRUE)
fixed |
Estimate a SSF Model
estimate( model, data, marginal = FALSE, concentrated = TRUE, initialization = c("Augmented_Robust", "Diffuse", "SqrtDiffuse", "Augmented", "Augmented_NoCollapsing"), optimizer = c("LevenbergMarquardt", "MinPack", "BFGS", "LBFGS"), precision = 1e-15, initialParameters = NULL )
estimate( model, data, marginal = FALSE, concentrated = TRUE, initialization = c("Augmented_Robust", "Diffuse", "SqrtDiffuse", "Augmented", "Augmented_NoCollapsing"), optimizer = c("LevenbergMarquardt", "MinPack", "BFGS", "LBFGS"), precision = 1e-15, initialParameters = NULL )
model |
the model |
data |
a matrix containing the data (one time series per column, time series dimension on the rows) |
marginal |
logical value used to specify whether the marginal likelihood definition is used (TRUE) or not (FALSE) during the optimization. The marginal likelihood is recommended when there is at least one variable that loads on a non-stationary latent variable and the loading coefficient needs to be estimated. |
concentrated |
logical value used to specify whether the likelihood is concentrated (TRUE) or not (FALSE) during the optimization |
initialization |
initialization method. |
precision |
indicating the largest likelihood deviations that make the algorithm stop. |
initialParameters |
Title
filtered_states_stdev(model)
filtered_states_stdev(model)
model |
Title
filtering_states_stdev(model)
filtering_states_stdev(model)
model |
Title
Title
loading(pos = NULL, weights = NULL) loading(pos = NULL, weights = NULL)
loading(pos = NULL, weights = NULL) loading(pos = NULL, weights = NULL)
pos |
defines the position of each one of the elements of the block of states defined.
|
weights |
defines the weights associated to each one of the state variables included in the block. |
obs |
Title
loading_cyclical(period, startpos)
loading_cyclical(period, startpos)
startpos |
Title
loading_periodic(period, startpos)
loading_periodic(period, startpos)
startpos |
Local Level
locallevel(name, variance = 0.01, fixed = FALSE, initial = NaN)
locallevel(name, variance = 0.01, fixed = FALSE, initial = NaN)
name |
name of the component. |
variance |
the value of the variance ( |
fixed |
boolean that triggers estimation of |
initial |
initial value of the level ( |
Local Linear Trend
locallineartrend( name, levelVariance = 0.01, slopevariance = 0.01, fixedLevelVariance = FALSE, fixedSlopeVariance = FALSE )
locallineartrend( name, levelVariance = 0.01, slopevariance = 0.01, fixedLevelVariance = FALSE, fixedSlopeVariance = FALSE )
name |
name of the component. |
levelVariance |
variance of the level ( |
fixedLevelVariance , fixedSlopeVariance
|
boolean that triggers
the estimation of the variances |
Modeling errors in surveys with overlapping panels
msae(name, nwaves, ar, fixedar = TRUE, lag = 1) msae2(name, vars, fixedvars = FALSE, ar, fixedar = TRUE, lag = 1) msae3(name, vars, fixedvars = FALSE, ar, fixedar = TRUE, k, lag = 1)
msae(name, nwaves, ar, fixedar = TRUE, lag = 1) msae2(name, vars, fixedvars = FALSE, ar, fixedar = TRUE, lag = 1) msae3(name, vars, fixedvars = FALSE, ar, fixedar = TRUE, k, lag = 1)
name |
name of the component. |
nwaves |
integer representing the number of waves |
ar |
matrix representing the covariance structure of the wave specific survey error. |
fixedar |
logical that triggers the estimation of the correlation patterns ( |
lag |
integer specifying the number of time periods (in the base frequency) that compose the survey period. This coincides with the number of time periods an individual has to wait between two different waves. Note that if the survey period is one quarter, all of them have already responded in the previous wave exactly 3 months ago (because individuals are always interviewed at the same stint during each survey period). |
Title
msignal(object, m, pos = NULL, stdev = FALSE)
msignal(object, m, pos = NULL, stdev = FALSE)
stdev |
Noise component
noise(name, variance = 0.01, fixed = FALSE)
noise(name, variance = 0.01, fixed = FALSE)
fixed |
Get Parameters of SSF Model
parameters(model)
parameters(model)
model |
Title
periodic(name, period, harmonics, variance = 0.01, fixedvariance = FALSE)
periodic(name, period, harmonics, variance = 0.01, fixedvariance = FALSE)
fixedvariance |
Title
## S3 method for class 'JD3STS' print(x, ...)
## S3 method for class 'JD3STS' print(x, ...)
x |
|
... |
Time Varying Regressors
reg(name, x, var = NULL, fixed = FALSE)
reg(name, x, var = NULL, fixed = FALSE)
x |
matrix containing the regressors |
fixed |
Title
reg_td( name, period, start, length, groups = c(1, 2, 3, 4, 5, 6, 0), contrast = TRUE, variance = 1, fixed = FALSE )
reg_td( name, period, start, length, groups = c(1, 2, 3, 4, 5, 6, 0), contrast = TRUE, variance = 1, fixed = FALSE )
fixed |
Title
sae(name, ar, fixedar = FALSE, lag = 1, zeroinit = FALSE)
sae(name, ar, fixedar = FALSE, lag = 1, zeroinit = FALSE)
zeroinit |
Title
sarima( name, period, orders, seasonal, parameters = NULL, fixedparameters = FALSE, var = 1, fixedvariance = FALSE )
sarima( name, period, orders, seasonal, parameters = NULL, fixedparameters = FALSE, var = 1, fixedvariance = FALSE )
fixedvariance |
Title
seasonal( name, period, type = c("Trigonometric", "Crude", "HarrisonStevens", "Dummy"), variance = 0.01, fixed = FALSE )
seasonal( name, period, type = c("Trigonometric", "Crude", "HarrisonStevens", "Dummy"), variance = 0.01, fixed = FALSE )
fixed |
Title
seasonalbreaks( y, period = NA, level = 1, slope = 1, noise = 1, seasonal = c("HarrisonStevens", "Trigonometric", "Dummy", "Crude", "Fixed", "Unused"), X = NULL, X.td = NULL )
seasonalbreaks( y, period = NA, level = 1, slope = 1, noise = 1, seasonal = c("HarrisonStevens", "Trigonometric", "Dummy", "Crude", "Fixed", "Unused"), X = NULL, X.td = NULL )
y |
input time series. |
period |
annual frequency. |
level |
-1 = no level, 0 = fixed level, 1 = sotchastic level |
slope |
|
noise |
|
seasonal |
Seasonal model |
X |
Regression variables (same length as y) or NULL |
X.td |
Groups of days for trading days regressors. The length of the array must be 7.
It indicates to what group each week day belongs.
The first item corresponds to Mondays and the last one to Sundays. The group used for contrasts (usually Sundays) is identified by 0. The other groups are identified by 1, 2,... n (<= 6).
For instance, usual trading days are defined by |
x<-rjd3toolkit::retail$BookStores seasonalbreaks(x)
x<-rjd3toolkit::retail$BookStores seasonalbreaks(x)
Title
signal(object, obs = 1, pos = NULL, loading = NULL, stdev = FALSE)
signal(object, obs = 1, pos = NULL, loading = NULL, stdev = FALSE)
stdev |
Retrieves the components of the model (univariate case) or the components corresponding to a given equation (multivariate case)
smoothed_components(model, equation = 1, fast = TRUE)
smoothed_components(model, equation = 1, fast = TRUE)
model |
Estimated state space model |
equation |
Equation containing the components |
fast |
if true, only the components are computed. Otherwise, their stdev are also computed (not returned but available for future use). |
A matrix with the components
Retrieves the stdev of the components of the model (univariate case) or of the components corresponding to a given equation (multivariate case)
smoothed_components_stdev(model, equation = 1)
smoothed_components_stdev(model, equation = 1)
model |
Estimated state space model |
equation |
Equation containing the components |
A matrix with the stdev of the components
Title
smoothed_states_stdev(model)
smoothed_states_stdev(model)
model |
Title
splines_daily(name, startYear, nodes, start = 1, variance = 1, fixed = FALSE)
splines_daily(name, startYear, nodes, start = 1, variance = 1, fixed = FALSE)
fixed |
Title
splines_regular( name, period, nnodes = 0, nodes = NULL, start = 1, variance = 1, fixed = FALSE )
splines_regular( name, period, nnodes = 0, nodes = NULL, start = 1, variance = 1, fixed = FALSE )
fixed |
Title
ssf(initialization, dynamics, measurement)
ssf(initialization, dynamics, measurement)
measurement |
Title
sts( y, X = NULL, X.td = NULL, level = 1, slope = 1, cycle = -1, noise = 1, seasonal = c("Trigonometric", "Dummy", "Crude", "HarrisonStevens", "Fixed", "Unused"), diffuse.regs = TRUE, tol = 1e-09 )
sts( y, X = NULL, X.td = NULL, level = 1, slope = 1, cycle = -1, noise = 1, seasonal = c("Trigonometric", "Dummy", "Crude", "HarrisonStevens", "Fixed", "Unused"), diffuse.regs = TRUE, tol = 1e-09 )
y |
input time series. |
X |
Regression variables (same length as y) or NULL |
X.td |
Groups of days for trading days regressors. The length of the array must be 7.
It indicates to what group each week day belongs.
The first item corresponds to Mondays and the last one to Sundays. The group used for contrasts (usually Sundays) is identified by 0. The other groups are identified by 1, 2,... n (<= 6).
For instance, usual trading days are defined by |
level |
-1 = no level, 0 = fixed level, 1 = sotchastic level |
slope |
|
cycle |
|
noise |
|
seasonal |
Seasonal model |
diffuse.regs |
|
tol |
x<-rjd3toolkit::retail$BookStores sts(x)
x<-rjd3toolkit::retail$BookStores sts(x)
Forecast with STS model
sts_forecast(y, model = c("none", "td2", "td3", "td7", "full"), nf = 12)
sts_forecast(y, model = c("none", "td2", "td3", "td7", "full"), nf = 12)
y |
Series |
model |
Model for calendar effects
|
nf |
number of forecasts |
fcasts<-sts_forecast(rjd3toolkit::ABS$X0.2.09.10.M)
fcasts<-sts_forecast(rjd3toolkit::ABS$X0.2.09.10.M)
Title
sts_outliers( y, period = NA, X = NULL, X.td = NULL, level = 1, slope = 1, noise = 1, seasonal = c("Trigonometric", "Dummy", "Crude", "HarrisonStevens", "Fixed", "Unused"), ao = TRUE, ls = TRUE, so = FALSE, cv = 0, tcv = 0, estimation.forward = c("Score", "Point", "Full"), estimation.backward = c("Point", "Score", "Full") )
sts_outliers( y, period = NA, X = NULL, X.td = NULL, level = 1, slope = 1, noise = 1, seasonal = c("Trigonometric", "Dummy", "Crude", "HarrisonStevens", "Fixed", "Unused"), ao = TRUE, ls = TRUE, so = FALSE, cv = 0, tcv = 0, estimation.forward = c("Score", "Point", "Full"), estimation.backward = c("Point", "Score", "Full") )
y |
input time series. |
period |
annual frequency. |
X |
Regression variables (same length as y) or NULL |
X.td |
Groups of days for trading days regressors. The length of the array must be 7.
It indicates to what group each week day belongs.
The first item corresponds to Mondays and the last one to Sundays. The group used for contrasts (usually Sundays) is identified by 0. The other groups are identified by 1, 2,... n (<= 6).
For instance, usual trading days are defined by |
level |
-1 = no level, 0 = fixed level, 1 = sotchastic level |
slope |
|
noise |
|
seasonal |
Seasonal model |
ao , ls , so
|
boolean indicating if additive outliers ( |
cv |
|
tcv |
|
estimation.forward |
|
estimation.backward |
x<-rjd3toolkit::retail$BookStores sts_outliers(x)
x<-rjd3toolkit::retail$BookStores sts_outliers(x)
Title
sts_raw( y, period = NA, X = NULL, X.td = NULL, level = 1, slope = 1, cycle = -1, noise = 1, seasonal = c("Trigonometric", "Dummy", "Crude", "HarrisonStevens", "Fixed", "Unused"), diffuse.regs = TRUE, tol = 1e-09 )
sts_raw( y, period = NA, X = NULL, X.td = NULL, level = 1, slope = 1, cycle = -1, noise = 1, seasonal = c("Trigonometric", "Dummy", "Crude", "HarrisonStevens", "Fixed", "Unused"), diffuse.regs = TRUE, tol = 1e-09 )
y |
|
period |
|
X |
|
X.td |
|
level |
|
slope |
|
cycle |
|
noise |
|
seasonal |
|
diffuse.regs |
|
tol |
Title
var_locallevel(name, std, scale = 1, fixed = FALSE, initial = NaN)
var_locallevel(name, std, scale = 1, fixed = FALSE, initial = NaN)
initial |
Title
var_locallineartrend( name, lstd, sstd = NULL, levelScale = 1, slopeScale = 1, fixedLevelScale = FALSE, fixedSlopeScale = FALSE )
var_locallineartrend( name, lstd, sstd = NULL, levelScale = 1, slopeScale = 1, fixedLevelScale = FALSE, fixedSlopeScale = FALSE )
fixedSlopeScale |
Title
var_noise(name, std, scale = 1, fixed = FALSE)
var_noise(name, std, scale = 1, fixed = FALSE)
fixed |
Time Varying Regressor
var_reg(name, x, stderr, scale = 1, fixed = FALSE)
var_reg(name, x, stderr, scale = 1, fixed = FALSE)
x |
Regression variable. Numerics |
stderr |
Standard error of the innovations of the coefficient (1 in extrapolation) |
scale |
Scaling factor |
fixed |
Fixed scaling factor |
x<-rjd3toolkit::retail$BookStores std<-rep(1, length(x)) std[c(20, 50, 150)]<-5 v<-var_reg("vx", x, std, 0.1)
x<-rjd3toolkit::retail$BookStores std<-rep(1, length(x)) std[c(20, 50, 150)]<-5 v<-var_reg("vx", x, std, 0.1)
Title
var_seasonal( name, period, type = c("Trigonometric", "Crude", "HarrisonStevens", "Dummy"), std, scale = 1, fixed = FALSE )
var_seasonal( name, period, type = c("Trigonometric", "Crude", "HarrisonStevens", "Dummy"), std, scale = 1, fixed = FALSE )
fixed |