Changeset 0c1edd7 in tol


Ignore:
Timestamp:
Aug 31, 2012, 9:31:52 AM (14 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
1627a73
Parents:
97f7850
Message:

Refs #1136
Modified Box Pierce statistic

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@5049 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tol/bmath/bstat
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tol/bmath/bstat/stat.cpp

    r97f7850 r0c1edd7  
    10301030
    10311031//--------------------------------------------------------------------
    1032 BDat BoxPierceLjungACF(const BArray<BDat>& acf, BInt s, BInt m)
    1033 
    1034 /*! Returns the Box-Pierce-Ljung statistic for first m autocorrelations
     1032BDat BoxPierceACF(const BArray<BDat>& acf, BInt m, BInt s)
     1033
     1034/*! Returns the Box-Pierce statistic for first m autocorrelations
    10351035 *  of a time series of length s
    10361036 */
    … …  
    10401040  BInt k;
    10411041  if(m>acf.Size()) { m=acf.Size(); }
    1042   for(k=0; k<m; k++)
     1042  for(k=1; k<=m; k++)
    10431043  {
    1044     Q += ((acf(k)^2)/BDat(s-k-1));
     1044    Q += (acf(k-1)^2);
     1045  }
     1046  Q *= BDat(s);
     1047  return(Q);
     1048}
     1049
     1050//--------------------------------------------------------------------
     1051double BoxPierceCenterMoment1(int m, int n)
     1052//--------------------------------------------------------------------
     1053{
     1054  int h = max(0,m-n/2);
     1055  double n2 = n*n;
     1056  double n3 = n*n2;
     1057  double EQBP = (m*(2*n3-(m+3)*n2+(m+1)*(2*m+1))-4*n*h*(2*m-n+1-h)) /
     1058                (2*n*(n2-1));
     1059  return(EQBP);
     1060}
     1061
     1062//--------------------------------------------------------------------
     1063double BoxPierceCenterMoment2(int m, int n)
     1064//--------------------------------------------------------------------
     1065{
     1066  double m2 = m*m;
     1067  double m3 = m*m2;
     1068  double m4 = m*m3;
     1069  double m5 = m*m4;
     1070  double n2 = n*n;
     1071  double n3 = n*n2;
     1072  double n4 = n*n3;
     1073  double n5 = n*n4;
     1074  double n6 = n*n5;
     1075  int zm = m%2;
     1076  int zn = n%2;
     1077  int q2 = max(0,2*m-n+1)/2;
     1078  int q3 = max(0,3*m-n+1)/2;
     1079  int q4 = max(0,4*m-n+1)/2;
     1080  double EQBP2 = (1/(n2-1)*(n+3)*(n+5)) *
     1081  (
     1082    (m/12*n2)*(
     1083      24*n*(-2-2*n-n2+3*n3-2*n4+n5)
     1084      +(35+114*n2+60*n3-261*n4+84*n5+12*n6)*m
     1085      -6*(-35-80*n-70*n2-14*n3+17*n4+2*n5)*m2
     1086      +(455+720*n+282*n2+24*n3+3*n4)*m3
     1087      -12*(-35-24*n+n2)*m4
     1088      +140*m5
     1089    )
     1090    +(4*n*(n-m)*(n-m-1)+6*m-2*n+3)*zm
     1091    +4*n*q4*(q4+1)*(4*q4-12*m+3*n-4)
     1092    +4*q3*(q3+1)*(2*q3*(q3+1)-(3*m-n+1)*(3*m-n+2)-1)
     1093    +(q2/6*n)*(
     1094      -(2*m-n+2)*(
     1095        (24-84*n-150*n2+59*n3+16*n4)
     1096        -2*m*(-63-54*n+63*n2+10*n3)
     1097        -6*m2*(-39-18*n+n2)
     1098        +156*m3
     1099      )
     1100      +zn*(
     1101        48-27*n-111*n2+43*n3+16*n4
     1102        -2*m*(-87-111*n+63*n2+10*n3)
     1103        -6*m2*(-47-18*n+n2)
     1104        +156*m3
     1105      )
     1106    )
     1107  );
     1108  return(EQBP2);
     1109}
     1110
     1111//--------------------------------------------------------------------
     1112BDat BoxPierceModACF(const BArray<BDat>& acf, BInt m, BInt s)
     1113
     1114/*! Returns the modified Box-Pierce statistic for first m autocorrelations
     1115 *  of a time series of length s
     1116 */
     1117//--------------------------------------------------------------------
     1118{
     1119  BDat QBP = BoxPierceACF(acf, m, s);
     1120  BDat EQBP  = BoxPierceCenterMoment1(m, s);
     1121  BDat EQBP2 = BoxPierceCenterMoment2(m, s);
     1122  BDat VQBP  = EQBP2-EQBP^2;
     1123  BDat QBPM = m+Sqrt(2*m/VQBP)*(QBP-EQBP);
     1124  return(QBPM);
     1125}
     1126
     1127//--------------------------------------------------------------------
     1128BDat BoxPierceLjungACF(const BArray<BDat>& acf, BInt m, BInt s)
     1129
     1130/*! Returns the Box-Pierce-Ljung statistic for first m autocorrelations
     1131 *  of a time series of length s
     1132 */
     1133//--------------------------------------------------------------------
     1134{
     1135  BDat Q = 0;
     1136  BInt k;
     1137  if(m>acf.Size()) { m=acf.Size(); }
     1138  for(k=1; k<=m; k++)
     1139  {
     1140    Q += ((acf(k-1)^2)/BDat(s-k));
    10451141  }
    10461142  Q *= BDat(s*(s+2));
  • tol/bmath/bstat/tol_bstat.h

    r97f7850 r0c1edd7  
    9090TOL_API BDat BoxPierceLjung       (const BArray<BDat>& vec, BInt m);
    9191TOL_API BDat BoxPierceLjungACF    (const BArray<BDat>& acf, BInt m, BInt s);
     92TOL_API BDat BoxPierceACF         (const BArray<BDat>& acf, BInt m, BInt s);
     93TOL_API BDat BoxPierceModACF      (const BArray<BDat>& acf, BInt m, BInt s);
     94
    9295
    9396//! To obtine the exponent of the best Box-Cox exponential transformation of a
Note: See TracChangeset for help on using the changeset viewer.