Skip to content
Rafat Hussain edited this page Jul 25, 2020 · 9 revisions

Seasonal ARIMA with Exogenous Variables Class and Functions

sarimax_object sarimax_init(int p, int d, int q,int P, int D, int Q,int s, int r,int imean, int N);

p - Number of Autoregressive coefficients
d - Number of times the series needs to be differenced
q - Number of Moving Average Coefficients
P - Number of Seasonal Autoregressive coefficients
D - Number of times the seasonal series needs to be differenced (s*D)
Q - Number of Seasonal Moving Average Coefficients
s - Seasonality/Period
r - Number of Exogenous Variables. (Important - Make sure it is set to 0 if none.
imean - 1 : Calculate mean/intercept. 0 : Otherwise
N - Length of Time Series

Execution

void sarimax_exec(sarimax_object obj, double *inp,double *xreg) ;

obj - SARIMAX object
inp - Input Time series of length N
xreg - Exogenous Variables of size r*N (row major order)

In case r=0 and no exogenous variables are present set xreg field to NULL

SARIMAX Object Parameters


        int N;// length of time series
	int Nused;//length of time series after differencing, Nused = N - d - s*D
	int method;
	int optmethod;
	int p;// size of phi
	int d;// Number of times the series is to be differenced
	int q;//size of theta
	int s;// Seasonality/Period
	int P;//Size of seasonal phi
	int D;// The number of times the seasonal series is to be differenced
	int Q;//size of Seasonal Theta
	int r;// Number of exogenous variables
	int M; // M = 0 if mean is 0.0 else M = 1
	int ncoeff;// Total Number of Coefficients to be estimated
	double *phi;// AR coefficients of size p
	double *theta;// MA coefficients of size q
	double *PHI;// Seasonal AR coefficients of size P
	double *THETA;// Seasonal MA coefficients of size Q
	double *exog;// Exogenous Variables coefficients of size r
  	double *vcov;// Variance-Covariance Matrix Of length lvcov
	int lvcov; //length of VCOV
	double *res;// Residual vector of size N
	double mean;// Mean
	double var;// Variance
	double loglik;
	double aic;
	int retval;
	int start;
	int imean;

SARIMAX Method (method)

0 - Conditional Method - Sum Of Squares + Exact Maximum Likelihood Method (Default)
1 - Exact Maximum Likelihood Method
2 - Conditional Method - Sum Of Squares

Optimization Method (optmethod)


optmethod accepts values between 0 and 7 where -

Method 0 - Nelder-Mead
Method 1 - Newton Line Search
Method 2 - Newton Trust Region - Hook Step
Method 3 - Newton Trust Region - Double Dog-Leg
Method 4 - Conjugate Gradient
Method 5 - BFGS (Default)
Method 6 - Limited Memory BFGS
Method 7 - BFGS Using More Thuente Method

Return Values

retval = 0 Input Error
retval = 1 Probable Success
retval = 4 Optimization Routine didn't converge
retval = 7 Exogenous Variables are collinear
retval = 10 Nonstationary AR part
retavl = 12 Nonstationary Seasonal AR part
retval = 15 Optimization Routine Encountered Inf/Nan Values

Functions associated with SARIMAX method


void sarimax_setMethod(sarimax_object obj, int value); // Sets ARIMA method. value accepts 0,1 and 2

void sarimax_setOptMethod(sarimax_object obj, int value); // Sets Optimization method. Value accepts 0,1,2,3,4,5,6 and 7

void sarimax_vcov(sarimax_object obj, double *vcov); // Returns variance-covariance matrix vcov

void sarimax_summary(sarimax_object obj); // Prints Seasonal ARIMA results and summary.

void sarimax_predict(sarimax_object obj, double *inp, double *xreg, int L,double *newxreg, double *xpred,
 double *amse); // L-step Prediction for time series inp (length N). newxreg is the length r * L matrix of exogenous
 variables. Set it to NULL if xreg is NULL ( r = 0). Returns length L output xpred and length L mean square error amse vectors

Deallocate Object Obj when the computation is finished

 sarimax_free(obj);

Examples

ARMA example for a stationary time series with no seasonal components and no exogenous variable.
SARIMA example with no exogenous variable.
ARMA example with exogenous variable.