19.0 BJEST Command The BJEST command allows estimation of ARIMA and TRANSFER function Box - Jenkins Models. For further references, see BJIDEN command. General form of the command. B34SEXEC BJEST parameters options$ MODEL Yvar = Xvar1 Xvar2 $ SERIESN VAR=Xvar1 NAME=(' ')$ OUTPUT paramaters options $ MODELN parameters options $ MODELI VAR=Xvar parameters options$ MODELPRE VAR=Xvar parameters options$ SPECTRAL options parameters $ RESTRICT parameters $ FORECAST options parameters $ BISPEC options parameters$ TRISPEC options parameters$ POLYSPEC options parameters$ REVERSE options parameters PGMCARDS$ input series data for forecasting here B34SRETURN$ B34SEEND$ If ARIMA model building is desired, only the MODEL and MODELN sentence need be supplied. If a transfer function model is desired, the MODEL, MODELN, MODELI and MODELPRE sentences are required. If forecasts are desired, the FORECAST sentence must be supplied. The OUTPUT sentence is used only when transfer function models are estimated. Unless otherwise indicated, all real input is limitedf to 8 digits. BJEST sentence options. NOEST - Sets not to estimate. The inputted model will be used to forecast. EST - Sets to estimate inputted model. This is the default. CPLOT - Causes all variables listed with PLOT parameter to be plotted using compressed (one page) plot option. CPLOT is the default. EPLOT - Causes all variables listed with PLOT parameter to be plotted using extended (more than one page) plot option. IAUTCR - Causes autocorrelations of cross correlation to be calculated as well as ACF of prewhitened series and residual. MPRINT - Suppresses printing of autocorrelations. MPRCCF - Suppresses printing of cross correlations. IWTPCC - Causes cross correlations to be plotted. MCSE - Suppresses SE calculations. IWTPA - Give plots of autocorrelations. IWBF - Uses backforecasting for estimation. PLOTR - Plot residuals. GRAPHR - Graph residual. Both PLOTR and GRAPHR cannot be given. SPECTRAL - Do spectral analysis on residuals. If SPECTRAL option is set the SPECTRAL sentence can be used to optionally change output. If SPECTRAL sentence is not present, spectral quantities are only listed. IRISK - Attempt to invert covariance matrix when 1/cond is close to zero. If IRISK is set, interpret results with caution. B34S could give a traceback. Parameters for BJEST sentence. LIST=(Xvar1 Xvar2) Specifies the variables mentioned in MODEL sentence to list. PLOT=(Xvar1 Xvar2) Specifies the variables mentioned in MODEL sentence to plot. NAC= n1 Max # of autocorrelations desired. Max = 150. Default=24. NPAC= n2 Max # of partial autocorrelations. Must be LE NAC. Default=NAC. NAPL= n3 Sets number of autocorrelations and partial autocorrelations printed per line. Max=12. Default = 12. NCHI= n4 Sets # of autocorrelations used to calculate chi square. NCHI must be LE NAC. If NCHI not specified, NCHI defaults to min(NAC, 24). NCC = n5 Sets maximum number of cross correlations. Max=54. Default=24. IRSAV=n6 Sets unit to save OBS #, fitted value, residual and data value and percent error. If IRSAV LT 0, file IRSAV is rewound before data is stored in SCA FSAVE format. If IRSAV = 44, then the file is rewound if this is the first access to the file in the job. SCA dataset name is RESIDUAL. Multiple calls will make multiple datasets with the same name. These can be renamed with B34S utility paragraph SCAINPUT or using the B34S Display Manager B34SIO menus. SMODEL(name) Sets file to save model discription for ARIMA model This file can be loaded with the macro command %b34sinc file(name) at run time. For example the code modelpre %b34sinc file('gas.mod')$ $ Note: The %b34sinc sentence ends with a $ and is in effect a sentence within a sentence until it goes away. Thus we see two $ $ before the sentence is parsed. IRC=key Output iterations and residuals key =SUPPRESS both iteration and residual output. This is the default. key =ITANDRES gives both iteration and residual output. key =RES gives residual output only. key =IT gives iteration output. MIT=n7 Set maximum number of iterations. Default=20. EPS1=r1 Sets max change in relative sum of squares before iteration stops. If this parameter is not given, this stopping rule is not used. Max of 10 digits is allowed. EPS2=r2 Sets max relative change in each parameter allowed before iteration stops. If both EPS1 and EPS2 and not present, EPS2 defaults to .004. Max of 10 digits allowed. IRWCNT=n8 Saves impulse response weights on unit IRWUNI with name SDATAn8. The BJIDEN TYPE=STARTVALUE will read these weights. If more than one set was saved, the name will be SDATAk where k = n8 + 1 etc. IRWUNI=n9 Sets unit to save impulse response weights in SCA format with name set by IRWCNT parameter. Default = 9. Must be set =0, =9 or GT 25. Note this file format is not an FSV format. It must be read with the SCAIO command NOT the SCAINPUT command. IBEGIN=n10 Sets initial observation for analysis. Default=1. IEND=n11 Sets last observation for analysis. Default=NOOB. AFSOPT=(key1,key2) Calls AFS Inc Extensions. Values for key: PIWEIGHT - Express Box-Jenkins model at PI weights. AGGUNCERT - Calculates aggregate forecast and aggregate uncertainty. See Box and Jenkins Appendix 5. LONGTRANS - Expresses transfer function as a weighted sum of past values of output series, the past of each input series and a random shock. This transformation is useful if different models are compared. MODEL sentence. The model sentence is used to indicate the left hand side and right hand side variables. For transfer funtion modeling, up to 5 right hand variables can be inputted. The right hand side variables can be continuous or of the 0-1 type. SERIESN sentence. SERIESN VAR=Xvar1 NAME=('Up to 65 characters here') $ The SERIESN sentence allows the user to optionally supply a longer name for the series than the variable name. If present the parameters VAR and NAME must be supplied. BISPEC sentence. The BISPEC sentence performs various nonlinearity, gaussianity and martingale tests suggested by Hinich. Any transformations called for on the BISPEC sentence are only for these tests and have no effect on any other options in other sentences in the command. The BISPEC sentence tests at which frequencies there is evidence of nonlinearity and whether there is memory (there is a Martingale). The form of the BISPEC sentence in the BTEST and BTIDEN commands is the same. To save space, detail for this sentence is listed only under the BTIDEN command help file. If the BISPEC sentence is given with no options or parameters, gaussianity and nonlinearity tests will be performed. TRISPEC sentence The TRISPEC command performs 4th order nonlinearity tests suggested by Hinich. Further detail on this sentence is listed under the BTIDEN command. POLYSPEC sentence The POLYSPEC command performs various nonlinearity tests suggested by Hinich within the sample. Further detail on this sentence is listed under the BTIDEN command. REVERSE sentence The REVERSE sentence performs various Time reversability tests suggested by Hinich and Rothman. Further detail in this sentence is listed under the BTIDEN command. OUTPUT sentence. The OUTPUT sentence is optionally used with transfer function model building to difference the left hand side variable. OUTPUT sentence parameters. DIF=(n1,n2)(n3,n4) - Specifies differencing operators. The first term inside ( ) is the number of differences, the second term is the order of differencing. There is a max of three differencing factors. MODELN sentence. The MODELN sentence allows the user to input the ARIMA model or the noise model depending on whether ARIMA models or transfer function models are estimated. The MODELN sentence is required. MODELN sentence parameters. P=(n1,n2)(n3,n4) - Inputs orders of AR model. Q=(n5,n6)(n7,n8) - Inputs orders of MA model. AR=(r1,r2)(r3,r4) - Inputs starting values for AR coefficients. Default=.1. MA=(n5,n6)(n7,n8) - Inputs starting values for MA coefficients. Default=.1. Note: The max number of coefficients in P and Q is limited to 10 in this release. The total number of factors in P and Q (# of ( ) ) is 6. DIF=(n1,n2)(n3,n4) - Specifies differencing operators. The first term inside ( ) is the number of differences, the second term is the order of differencing. There is a max of three differencing factors. AVEPA=r1 - Sets average for series. Assumed= 0.0 if no differencing, not needed if there is differencing. PLAM=r2 If r2 = 1.0, the data is unchanged. This is the default. If r2 = 0.0, the newseries = ln(oldseries + TM). If r2 NE 0 and NE 1, newseries = (oldseries + TM)**r2. Note: up to 7 PLAM parameters can be tried. The B34S BJEST option will search among those requested. For example if PLAM=(1.3,1.4), Box cox transformations will be tried for exponents 1.3 and 1.4. TM = r3 Specifies constant to add to data to allow transform. TREPA=r4 Specifies trend estimate for series. MODELI sentence. The MODELI sentence is used to enter the input model. The MODELN sentence is required if transfer function models is desired. One MODELI sentence must be supplied for each right hand variable. MODELI sentence parameters. VAR=Xvar The VAR parameter indicates the input variable for which the MODELI sentence refers. The VAR parameter is required. DENOM=(n1,n2)(n3,n4) - Inputs orders of denominator model. NUM =(n5,n6)(n7,n8) - Inputs orders of numerator model. The NUM parameter MUST be supplied and the first number in the first ( ) must be zero. If a lag is desired, use the LAG parameter. DENOMC=(r1,r2)(r3,r4) - Inputs starting values for denominator coefficients. Default = .1. NUMC =(n5,n6)(n7,n8) - Inputs starting values for numerator coefficients. Default=.1. Note: The max number of coefficients in P and Q is limited to 10 in this release. The total number of factors in P and Q (# of ( ) ) is 6. DIF=(n1,n2)(n3,n4) - Specifies differencing operators. The first term inside ( ) is the number of differences, the second term is the order of differencing. There is a max of three differencing factors. LAG=n6 - Specifies the lag for the input variable. SERIES=key - Sets type of input series. Possible values for key are: CONTINUOUS for continuous series. NUN01 for 0-1 variable with potential differences in numerator. DENOM01 for 0-1 variable with potential differences in the denominator. MODELPRE sentence. The MODELPRE sentence allows the user to input the prewritening model, estimated in a prior run, to filter the X series and be applied to the Y series. If NSERIE series are listed in the VAR sentence and TYPE=TRANSI, there must be NSERIE - 1 MODELPRE sentences and one OUTPUT sentence. Variables to prewhiten and cross correlate are listed on the PCROSS sentence. The one filter method will be used if in the PCROSS sentence the second of the two series within the ( ) is the last series listed on the VAR sentence. If this is not the case, the two filter method of analysis will be used. Differencing for the Y series (the series filtered with the X series filter) will be input on the OUTPUT sentence. MODELPRE sentence parameters. VAR=Xvar - Sets series name. VAR is a required parameter. P=(n1,n2)(n3,n4) - Inputs orders of AR model. Q=(n5,n6)(n7,n8) - Inputs orders of MA model. AR=(r1,r2)(r3,r4) - Inputs values for AR coefficients. MA=(n5,n6)(n7,n8) - Inputs values for MA coefficients. Note: The max number of coefficients in P and Q is limited to 10 in this release. The total number of factors in P and Q (# of ( ) ) is 6. DIF=(n1,n2)(n3,n4) - Specifies differencing operators. The first term inside ( ) is the number of differences, the second term is the order of differencing. There is a max of three differencing factors. AVEPA=r1 - Sets average for series. Assumed= 0.0 if is no differencing, not needed if there is differencing. PLAM=r2 If r2 = 1.0, the data is unchanged. This is the default. If r2 = 0.0, the newseries = ln(oldseries + TM). If r2 NE 0 and NE 1, newseries = (oldseries + TM)**r2. TM = r3 Specifies constant to add to data to allow transform. TREPA=r4 Specifies trend estimate for series. SPECTRAL sentence. SPECTRAL options parameters. If the keyword SPECTRAL is given in the BJEST sentence the SPECTRAL sentence is used to control spectral analysis of series listed as inputs and the residual. If the SPECTRAL sentence is not supplied, spectral values will only be listed. . Options on the SPECTRAL sentence. DETREND - Set to detrend the series prior to spectral analysis. PUNCHE - Punches all spectral quantities on UNIT in format 5E16.8. PUNCHA - Punches all spectral qunatities on UNIT in format 10A4. Parameters on the SPECTRAL sentence, NFREQ = n1 Sets # of frequencies. Defaults to NCC. XINDSP1= r1 Sets constant time interval. Default = 1.0 . XINDSP2= r2 If set, prewhitens all series with an AR(1) model with coef = r2. PLOT=(key1, key2) Controls plotting of spectral quantities. Keywords supported with PLOT parameter. COSPEC - Plot cospectrum. QSPEC - Plot quadrature spectrum. ACROSSPEC - Plot Amplitude of cross spectrum. PHASESPEC - Plot phase spectrum. ATRANSXY - Plot amplitude of transfer function from series X to Y. ATRANSYX - Plot amplitude of transfer function from series Y to X. COHSQ - Plot coherency square. POWERSPX - Plot power spectrum for X. POWERSPY - Plot power spectrum for Y. UNIT = n2 Unit for punching. Default = 7. MODELPRE sentence. RESTRICT sentence. The RESTRICT sentence allows the user to optionally restrict up to 10 parameters to be a constant multiple of other parameters. There can be up to 10 RESTRICT sentences in the BJEST paragraph. All parameters must be set. RESTRICT sentence parameters. MUPAR1=n1 - Set to input series number for parameter to be considered a constant multiple. MUPAR2=n2 - Set to factor number. Note that AR (denominator) factors come before MA (numerator) factors. MUPAR3=n3 - Set to parameters # within the factor. MUPAR4=n4 - Set to input series number for second parameter. MUPAR5=n5 - Set to factor number for second parameter. MUPAR6=n6 - Set to parameter # within factor for second parameter. CONPAR=r1 - Set to constant multiple desired between the two transfer function parameters. "Fix" parameters = constant multiple multiplied by the variable parameter. MAX of 8 digits is allowed. FORECAST sentence. The FORECAST sentence sets parameters for forecasting. No forecasting will be done unless the FORECAST sentence is present. The parameters NF and NT are required. FORECAST sentence options. IWTPF - Causes the forecasts to be plotted. SCAUNIT - Causes the forecasts to be saved in an SCA FSAVE file on unit 44. The SCA dataset name is FORECn. FORECAST sentence parameters. NF=n1 - Sets number of forecasts to make at each origin. Max=50. NT=(n2,n3) - Sets time origins for forecasting. Max = 3. If forecasting is desired, at least one origin must be supplied. ICI=n5 - Must be coded = 1,2,3,4,5 for forecast confidence intervals 50,75,90,95,99. Default=4. IIUX=n6 - Logical unit for entering forecasts of input series. This is needed if the input series is of the 0-1 type. If an input variable is not specified with the ISP parameter, the prewhitening model is used to forecast the input series. Input will be free format on unit IIUX. If ISP is not specified, user can input forecasts between PGMCARDS$ - B34SRETURN$ or DATACARDS$ - B34SRETURN$ sentences. NU=n7 - Sets number of new observations, beyond original NOOB, to be read from B34S, if available. IIIUX - not used in this release. ISP=(Xvark,Xvarj) - Sets names of input series optionally read in on unit IIUX. Usage note: In almost all cases, the only parameters set on FORECAST sentence are NF and NT. Unless IIUX is given, values for the 0-1 series will be read free format between the PGMCARDS$ and B34SRETURN$ sentences. If IIUX is set GT 0, then a format card must proceed each set of values for the 0-1 variable. If IIUX is set LT 0, then free format reading will be used from unit IIUX. Assume we are using free format option (the default) and have three origins and want to forecast 10 series. Then for each 0-1 variable given in the ISP sentence, 30 values must be input. It is important to input the correct number of observations since BJEST sentence does not check values. An will stop B34S execution. ************************ Sample jobs. ARIMA estimation and forecasting. b34sexec bjest $ model gasin$ modeln p=(1,2,3) ar=(1.0,-1.0,.5) avepa=.5 $ forecast nf=24 nt=(296)$ b34seend$ Transfer function for one input model. The prewhitening model for GASIN has been supplied to perform diagnostic checking of the model. b34sexec bjest $ model gasout=gasin $ modeln p=(1,2) ar=(1.0, -.5) avepa=10.0$ modeli var=gasin lag=3 num=(0,1,2) denom=(1,2) numc=(-.5, .2, .5) denomc=(.5,.1)$ modelpre var=gasin p=(1,2,3) ar=(1.97494,-1.3732,.3424) avepa=-.061 $ forecast nf=24 nt=(296)$ b34seend$ Example of Box-Tiao (1975) Ozone Model /; /; Box Tiao JASA 1975 Vol 70 Number 349 March 1975 pp 70-79 /; Intervention Analysis with Applications to Economic and /; Environmental Problems /; /; SAS model taken from Example 3.4 on page 177 of SAS ETS / User's Guide 1993 /; /; Note that SAS ML did not converge!!!!! /; SAS CLS is the B34S result /; /; This example illustrates that method of estimation matters! /; ML can cause problems /; /; In 1993 SAS did not "flag" problems of ML. /; In SAS version 9 these were flagged. /; /; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /; /; %b34slet runsas=1; b34sexec options ginclude('b34sdata.mac') member(btozone); b34srun; b34sexec list; b34srun; /$ b34sexec bjest ; model ozone =intv1 intv2 intv3; modeln q=(1)(12); modeli var=intv1 num=(0) series=nun01 dif(1,12); modeli var=intv2 num=(0) series=nun01 ; modeli var=intv3 num=(0) series=nun01 ; output dif(1,12); modelpre var=intv1 ; modelpre var=intv2 ; modelpre var=intv3 ; b34srun; %b34sif(&runsas.ne.0)%then; b34sexec options open('testsas.sas') unit(29) disp=unknown$ b34srun$ b34sexec options clean(29) $ b34seend$ b34sexec pgmcall idata=29 icntrl=29$ sas $ * sas commands next ; pgmcards$ proc arima; identify var=ozone(12) crosscorr=(intv1(12) intv2 intv3) ; estimate q=(1)(12) input=(intv1 intv2 intv3) noconstant method=ml itprint; estimate q=(1)(12) input=(intv1 intv2 intv3) noconstant method=uls itprint; * Default Method; estimate q=(1)(12) input=(intv1 intv2 intv3) noconstant method=cls itprint; forecast lead=12; b34sreturn$ b34srun $ b34sexec options close(29)$ b34srun$ /$ the next card has to be modified to point to sas location /$ be sure and wait until sas gets done before letting b34s /$ resume /$*********************************************************** b34sexec options dodos('start /w /r sas testsas' ) dounix('sas testsas' ) $ b34srun$ b34sexec options npageout noheader writeout(' ','output from sas',' ',' ') writelog(' ','output from sas',' ',' ') copyfout('testsas.lst') copyflog('testsas.log') dodos('erase testsas.sas','erase testsas.lst', 'erase testsas.log') dounix('rm testsas.sas','rm testsas.lst', 'rm testsas.log') $ b34srun$ b34sexec options header$ b34srun$ %b34sendif; Example of Box-Tiao (1975) intervention Model # 2. Results for B34S and SCA agree. Box-Tiao results differ slightly. %b34slet runsca=1; /; /; Box-Tiao jasa (1975) example # 2 /; /; Box Tiao JASA 1975 Vol 70 Number 349 March 1975 pp 70-79 /; Intervention Analysis with Applications to Economic and /; Environmental Problems /; answers replicate sca. answers not same as box-tiao /; results suggest phase i1 worked but phase ii did not /; model is quite simple /; b34sexec options ginclude('b34sdata.mac') member(btcpi); b34srun; /; b34sexec list; b34srun; b34sexec bjest ; model cpi =int1 int2; modeln q=1 ; modeli var=int1 num=(0) series=nun01 dif(1,1); modeli var=int2 num=(0) series=nun01 dif(1,1); output dif(1,1); modelpre var=int1 ; modelpre var=int2 ; b34srun; %b34sif(&runsca.ne.0)%then; b34sexec options open('sca.dat') disp=unknown unit(28)$ b34srun$ b34sexec options open('sca.cmd') disp=unknown unit(29)$ b34srun$ b34sexec options clean(28)$ b34srun$ b34sexec options clean(29)$ b34srun$ b34sexec pgmcall$ sca scafname=mydata$ pgmcards$ /$#==myrun --- these commands are required to load the b34s data. --- assign file 18. attrib access(read). external 'sca.dat'. call procedure is mydata. file is 18. --- --- user can place any sca commands after here. a number --- of sample setups can be uncommented --- print age, ecg, chd, cat, wt --- crosstab cat, age. --- crosstab age, ecg, chd, cat. weight is wt. --- print gasin, gasout. --- acf gasin. --- regress variables are gasout gasin --- sca expert commands --- iarima gasout. hold residuals(res) --- estim utsmodel. method is exact. --- forecast utsmodel. --- var identification --- ccm gasin, gasout. maxlag is 12. --- stepar gasin, gasout. arfits are 1 to 6. @ --- rccm are 1,2. output level(detailed). --- fsave series1. file is 'my.fsv'. dataset is test. -- -- -- sets up sca graph program -- graph gasin,gasout. -- iarima cpi . utsmodel name is cpimdl. @ model is cpi((1-b))=(w1)int1(binary,(1-b)) + @ (w2)int2(binary,(1-b))+(1-theta*b)noise. uestim model cpimdl. hold residuals(rcpi). output level(verbose). uestim model cpimdl. method is exact. hold residuals(rcpi). @ output level(verbose). stop. return /$#== b34sreturn$ b34srun$ b34sexec options close(28)$ b34srun$ b34sexec options close(29)$ b34srun$ b34sexec options dounix('sca sca.cmd > sca.out') dodos('scaw32 10000 /f:sca.cmd /p:myrun /o:sca.out') $ b34srun$ b34sexec options npageout writeout('output from sca',' ',' ') copyfout('sca.out') dodos('erase sca.cmd','erase sca.out','erase sca.dat') dounix('rm sca.cmd','rm sca.out','rm sca.dat') $ b34srun$ For further detail on generating test problems, see the LP command in the DATA step.