Function to Perform polynomail fit on the given X and Y data points. The function will normailize X data first, and then call ocmath_multiple_linear_regression(), which is the main computational engine, and finally correct the variance-covariance matrix.
int ocmath_polynomial_fit( int nSize, const double * pX, const double * pY, const double * pWeightIn, int nOrder, const LROptions * psLROptions, FitParameter * psFitParameter, int nSizeFitParams, RegStats * psRegStats = NULL, RegANOVA * psRegANOVA = NULL, double * pCov = NULL, double * pCorr = NULL, double * pH = NULL, int nSizeCovCorr = -1 )
Returns STATS_NO_ERROR or positive on successful exit and a negative STATS error code on failure.
LARGE_X_NORMALIZED(1): the independent data have large value and small range, so are normalized first.
Error Codes:
STATS_ERROR_ARRAY_TOO_SMALL(-99): nSizeCovCorr < (nOrder+1)*(nOrder+1)
STATS_INPUT_NULL_POINTER(-156): pX and pY must not be empty.
STATS_ERROR_TOO_FEW_DATA_PTS(-165): nSize must not be less than 2
STATS_ERROR_SETTING(-151): nOrder must not be less than 1
STATS_ERROR_SVD_FAIL(-179): The singular value decomposition is failed
STATS_ERROR_RANK_DEFICIENT(-180): The pX is not full rank.
STATS_ERROR_BAD_WEIGHT(-108): Some data of the weight are less than zero
EX1
void ocmath_polynomial_fit_ex1() { int nOrder; int nRet; //parameters required by stats_polynomial_fit LROptions sLROptions; //LROptionsNANUM(sLROptions); RegStats sRegStats; RegANOVA sRegANOVA; int nSize = 10; vector vX, vY; vX.SetSize(10); vY.SetSize(10); for(int i=0; i<nSize; i++) // Y = X^2 { vX[i] = i+1; vY[i] = (i+1)*(i+1); } double vW[10]; for(i=0; i<nSize; i++) { vW[i] = 1; } sLROptions.Confidence = 0.95; nOrder = 2; double pCov[9], pCorr[9] ; int nParam = (sLROptions.FixIntercept) ? nOrder : nOrder + 1; FitParameter sFitParameter[3]; nRet = ocmath_polynomial_fit(nSize,vX,vY,vW,nOrder,&sLROptions,sFitParameter,nParam,&sRegStats,&sRegANOVA,pCov,pCorr); if (nRet == LARGE_X_NORMALIZED) printf("x data are normalized!\n"); else if (nRet < STATS_NO_ERROR) printf("Error!\n"); }
origin.h