On Tue, Nov 29, 2011 at 10:01 PM, G?rard Lochon <[email protected]> wrote:
> >
> > > Anyone know of a VFP friendly Least Square Regression Routine?  Free is
> > > good.
> > >

Sorry for the delay:

LPARAMETERS tcTerms

lnLinest = 0

lnTotTerms = GETWORDCOUNT( tcTerms, [,])
IF lnTotTerms < 3
        RETURN lnLinest
ENDIF

lnSx = 0.0
lnSy = 0.0
lnSy = 0.0
lnSxx = 0.0
lnSyy = 0.0
lnSxy = 0.0

= ALINES( laTerms, tcTerms, 1, [,])

lnCount = 0
FOR EACH lcTerm IN laTerms
        lnCount = lnCount + 1
        
        lnTerm = VAL( ALLTRIM( lcTerm))
        
        lnSx = lnSx + lnCount
        lnSy = lnSy + lnTerm
        lnSxx = lnSxx + lnCount * lnCount
        lnSyy = lnSyy + lnTerm * lnTerm
        lnSxy = lnSxy + lnCount * lnTerm
ENDFOR

lnDet = ( lnSxx * lnTotTerms) - ( lnSx * lnSx)
lnA = ( ( lnSxy * lnTotTerms) - ( lnSy * lnSx)) / lnDet
lnB = ( ( lnSxx * lnSy) - ( lnSx * lnSxy)) / lnDet

lnMeanErr = 0.0
lnResidual = 0.0

lnCount = 0
FOR EACH lcTerm IN laTerms
        lnCount = lnCount + 1
        
        lnTerm = VAL( ALLTRIM( lcTerm))

        lnMeanErr = lnMeanErr + ( lnTerm - ( lnSy / lnTotTerms))^2
        lnResidual = lnResidual + ( lnTerm - lnA * lnCount - lnB)^2     
ENDFOR

lnRR = 1 - lnResidual / lnMeanErr
lnSS = lnResidual / ( lnTotTerms - 2)

RETURN CAST( lnA as Numeric( 10, 5))

*!*     ? [Slope = ] + TRANSFORM( CAST( lnA as Numeric( 10, 5)))
*!*     ? [Y-Int = ] + TRANSFORM( CAST( lnB as Numeric( 10, 5)))
*!*     ? [R     = ] + TRANSFORM( CAST( lnRR as Numeric( 10, 5)))

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/capuo4g7pfdn9ym0jjwbhbh15at2orfj6fi66odkizmsjy9c...@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to