/* tresid.c CCMATH mathematics library source code. * * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. * This code may be redistributed under the terms of the GNU library * public license (LGPL). ( See the lgpl.license file for details.) * ------------------------------------------------------------------------ */ /* Test: resid (analysis of time series model residuals) Input parameter: dfile -> name of binary file containing time series model residual data [created by tmest or tfmest] Prompted inputs: at prompt 'lags / ' enter lag -> integer: maximum lag for autocorrelation computation at prompt 'xmin xmax bins ? ' enter xmin -> minimum for residual histogram xmax -> maximum for residual histogram nb -> number of histogram bins at prompt ' Print Power Spectra ? (y/n) ' enter y to print the power spectra n for no power spectra output */ #include "ccmath.h" double *x; int nmax; void main(int na,char **av) { int j,n,lag,nb,*ph,cks[2]; double xa,xb,d,*pac; FILE *fp; char cfg[4]; if(na!=2){ printf("para: dfile\n"); exit(-1);} fprintf(stderr,"lags ? "); scanf("%d",&lag); fprintf(stderr,"xmin xmax bins ? "); scanf("%lf %lf %d",&xa,&xb,&nb); /* read residual data file */ fp=fopen(*++av,"rb"); printf(" input file: %s\n",*av); fread((void *)&nmax,sizeof(int),1,fp); x=(double *)calloc(nmax,sizeof(*x)); n=fread((void *)x,sizeof(double),nmax,fp); printf(" series size= %d\n",n); /* perform analysis of model residuals */ n=resid(x,n,lag,&pac,nb,xa,xb,&ph,cks); printf(" second moment= %10.5f\n",pac[0]); printf(" lag autocorrelation\n"); for(j=1; j<=lag ;++j) printf(" %2d %10.6f\n",j,pac[j]); printf("\n series histogram\n"); d=(xb-xa)/nb; for(j=0; j\n\n",ph[-1],ph[nb]); printf(" Kolmogorov-Smirnov Test\n"); printf(" %d outside .25 bounds\n",cks[0]); printf(" %d outside .05 bounds\n\n",cks[1]); fprintf(stderr,"Print Power Spectra ? (y/n) "); scanf("%s",cfg); if(cfg[0]=='y'){ printf("\n Power Spectra\n"); for(j=0,n/=2; j Kolmogorov-Smirnov Test 0 outside .25 bounds 0 outside .05 bounds */