Skip to contents

Estimate DFM with Expectations-Maximization algorithm

Usage

estimate_em(
  dfm,
  data,
  standardized = FALSE,
  input_standardization = NULL,
  pca_init = TRUE,
  max_iter = 100,
  eps = 1e-09,
  re_estimate = TRUE
)

Arguments

dfm

an object of class 'JD3_DfmModel'. Typically generated by the create_model() function.

data

an mts object.

standardized

Boolean. Indicate whether the input series were already standardized or not. Default is FALSE, meaning that a standardization of the series will be preliminary applied as part of the process.

input_standardization

Matrix. Mean and standard deviation of the variables to consider for the pre-processing step of standardization. Default is NULL, meaning that they will be re-calculated based on the data. Typically, it can be filled with the output of the function `get_results()$preprocessing$sample_mean_stdev` applied on a previous estimate of the model. If provided manually, it must be a two columns matrix with the mean in the first column and the standard deviation in the second column. In the rows, the order of the variables should also be respected (similar to the data). Note that this argument must be filled if the re_estimate argument is set to FALSE. On the other hand, it is ignored if the standardized argument is set to TRUE.

pca_init

Boolean. Indicate whether a principal components analysis is performed beforehand and used as initial condition for the EM algorithm.

max_iter

Integer. Maximum number of iterations.

eps

Numeric. EM algorithm is run until the percentage likelihood does not increase by more than the eps value (1e-9 is the default) or until the maximum number of iterations is hit.

re_estimate

Boolean. Indicate whether the model will be re-estimated or not. Default is TRUE. Could be set to FALSE if, for some reasons during the production process, we wanted to freeze to model for some periods of time. It is not recommended to freeze the model for a long period.

Value

an object of class 'JD3_DfmEstimates'

Examples

set.seed(100)
data<-ts(matrix(rnorm(500), 100, 5), frequency = 12, start = c(2010,1))
data[100,1]<-data[99:100,2]<-data[(1:100)[-seq(3,100,3)],5]<-NA
dfm <- create_model(nfactors=2,
                    nlags=2,
                    factors_type = c("M", "M", "YoY", "M", "Q"),
                    factors_loading = matrix(data=TRUE, 5, 2),
                    var_init = "Unconditional")
est_em<-estimate_em(dfm, data)

#est_em<-estimate_em(dfm, data, re_estimate=FALSE) # model not re-estimated