newfoo#

Purpose#

Solves the nonlinear programming problem.

Format#

out = newfoo(&fct, par, y[, ctl])#
Parameters:
  • &fct (function pointer) – pointer to a procedure that computes the function to be minimized. The first input to this procedure must be an instance of structure of type PV.

  • par (Vector) – Contains starting values for parameters to be estimated. This parameter vector is used in the updated function to update the state space system matrices.

  • y (Vector) – Observed data.

  • ctl (struct) –

    Optional input. instance of an ssControl structure. Normally an instance is initialized by calling ssControlCreate() and members of this instance can be set to other values by the user. For an instance named ctl, the members are:

    sctl.param_names

    String array, parameter names.

    sctl.stationary_vars

    Vector, specifies the index of the variables which should be constrained stationary.

    sctl.positive_vars

    Vector, specifies the index of the variables which should be constrained positive.

    sctl.ctl

    Instance of a cmlmtControl structure, used for fine-tuning maximum likelihood estimation. Further information provided in the cmlmt documentation.

    sctl.ssm

    Instance of a ssModel structure, contains the state space system matrices used in the kalmanFilter(). Contains the following members:

    ssm.Z

    k_endog x k_states, transition matrix.

    ssm.d

    k_endog x 1, observation intercept.

    ssm.H

    k_endog x k_endog, observation disturbance covariance.

    ssm.T

    k_states x k_states, design matrix.

    ssm.c

    k_states x k_states, state intercept.

    ssm.R

    k_states x k_posdef, selection matrix.

    ssm.Q

    k_states x k_posdef, state disturbance covariance.

    ssm.a_0

    k_states x 1, initial prior state mean.

    ssm.p_0

    k_states x k_states, initial prior state covariance.

Returns:

out (struct) –

an instance of an structNameout structure. For an instance named out, the members are:

sctl.final_params

String array, parameter names.

sctl.resid

Vector, specifies the index of the variables which should be constrained stationary.

sctl.fitted

Vector, specifies the index of the variables which should be constrained positive.

sctl.df_model

Vector, specifies the index of the variables which should be constrained positive.

sctl.df_resid

Vector, specifies the index of the variables which should be constrained positive.

sctl.numObs

Vector, specifies the index of the variables which should be constrained positive.

sctl.mleResults

Instance of a cmlmtResults structure, used for fine-tuning maximum likelihood estimation. Further information provided in the cmlmt documentation.

sctl.kfResults

Instance of a kalmanOut structure, contains the results from the kalmanFilter().

kout.filtered_state

Matrix, k_endog x numObs, filtered states.

kout.filtered_state_cov

Array, numObs x k_endog x k_endog, filtered state covariances.

kout.predicted_state

Matrix, k_endog x (numObs+1), predicted states.

kout.predicted_state_cov

Array, numObs x k_endog x k_endog, predicted state covariances.

kout.forecast

Matrix, k_endog x numObs, forecasts.

kout.forecast_error

Matrix, k_endog x numObs, forecast error.

kout.forecast_error_cov

Array, numObs x k_endog x k_endog, forecast error covariances.

kout.loglikelihood

Matrix, k_endog x (numObs+1), computed loglikelihood.

sctl.ssmFinal

Instance of a ssModel structure, contains the state space system matrices used in the kalmanFilter(). Contains the following members:

ssm.Z

k_endog x k_states, transition matrix.

ssm.d

k_endog x 1, observation intercept.

ssm.H

k_endog x k_endog, observation disturbance covariance.

ssm.T

k_states x k_states, design matrix.

ssm.c

k_states x k_states, state intercept.

ssm.R

k_states x k_posdef, selection matrix.

ssm.Q

k_states x k_posdef, state disturbance covariance.

ssm.a_0

k_states x 1, initial prior state mean.

ssm.p_0

k_states x k_states, initial prior state covariance.

Examples#

// Set up procedure for updating SS model
// structure
proc (0) = updateSSModel(struct ssModel *ssmod, param);

 // Set up kalman filter matrices
 ssmod->T =  param[1 2]'|(1~0);
 ssmod->Q[1, 1] = param[3];

endp;

Remarks#

The update function is a required user-provided procedure which specifies how the state space system matrices should be updated with the underlying model parameters.

The update function must always take the same inputs:

  • The first input is a pointer to a ssModel structure which contains the state space system matrices.

  • The second input is a vector of parameters.

The update function should only specify system matrices which contain parameters, it should not specify fixed system matrices.

For example, we might have the following update function specifying how the parameters of a model should be placed in the state space matrices:

proc (0) = updateSSModel(struct ssModel *ssmod, param);

 // Set up kalman filter matrices
 ssmod->T =  param[1 2]'|(1~0);
 ssmod->Q[1, 1] = param[3];

endp;

Source#

ssmain.src