/* DEC *LinearEstimate(pCorr, pLinA, pLinB, pSrcX, pSrcY, wSize); * * ARGUMENT * DEC *pCorr, *pLinA, *pLinB; * DEC **pSrcX, **pSrcY; * int wSize; * * DESCRIPTION * Determines the least squares line y = A + B * x and the * linear correlation coefficient of a given set of (X, Y) values. * The wSize (X, Y) values, where wSize > 1, are stored in arrays * pSrcX and pSrcY. The correlation coefficient is put in pCorr. * The value A is put in the global pGMStatA, along with pLinA, * while B is put in the global pGMStatB and pLinB. Storing A and * B in globals allow their later usage in PredictX and PredictY. * The correlation coefficient is returned. * * SIDE EFFECTS * None. * * RETURNS * Returns pointer to the correlation coefficient if successful, * otherwise returns GM_NULL. * * POSSIBLE ERROR CODES * * GM_NULLPOINTER * GM_ARGVAL * GM_OVERFLOW * GM_UNDERFLOW * * AUTHOR * Jared Levy * Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved. * * MODIFICATIONS * */ #include #include "gm.h" #include "gmsystem.h" DEC *LinearEstimate(pCorr, pLinA, pLinB, pSrcX, pSrcY, wSize) DEC *pCorr, *pLinA, *pLinB; DEC **pSrcX, **pSrcY; int wSize; { int i; DEC dSumX, *pSumX=&dSumX, dSumY, *pSumY=&dSumY; DEC dSumXX, *pSumXX=&dSumXX, dSumYY, *pSumYY=&dSumYY; DEC dSumXY, *pSumXY=&dSumXY, dSize, *pSize=&dSize; DEC dProd, *pProd=&dProd, dProd2, *pProd2=&dProd2; DEC dVarX, *pVarX=&dVarX, dVarY, *pVarY=&dVarY; DEC dNum, *pNum=&dNum, dDen, *pDen=&dDen; _MacStart(GM_LINEST); if (!pSrcX||!pSrcY||!pCorr||!pLinA||!pLinB) { _MacErr(GM_NULLPOINTER); _MacRet(GM_NULL); } if (wSize<=1) { _MacErr(GM_ARGVAL); _MacRet(GM_NULL); } for (i=0; i