Thread: LinEst function
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jerry W. Lewis Jerry W. Lewis is offline
external usenet poster
 
Posts: 837
Default LinEst function

The limit for LINEST is 17 independent variables. MINVERSE can invert a
52x52 matrix, so you could potentially handle 52 independent variables
by manually forming and solving the Normal Equations. I would not trust
the numerical properties of such a solution, though.

Since Excel 2003 has greatly improved the numerical accuracy of LINEST,
it will be interesting to see if the next version of Excel removes this
apparently arbitrary hardcoded limit in LINEST.

Jerry

Tushar Mehta wrote:

It is possible there is some limit, but since I just tested with 7
independent variables, it is not 6. My guess would be your variables
are not independent. One of the Xi vectors is a linear combination of
the others.

Also, a tip about transferring data across the XL-VBA interface. For
my test I had x values in A1:G14 and the Y values were in I1:I14. I
wanted the result of linest in A24:H28. The code below does the job:

Sub testIt()
Dim X As Variant, Y As Variant, Rslt As Variant
X = Range(Cells(1, 1), Cells(14, 7))
Y = Range(Cells(1, 9), Cells(14, 9))
Rslt = Application.WorksheetFunction.LinEst(Y, X, True, True)
Range(Cells(24, 1), Cells(28, 8)) = Rslt
End Sub

Do note that all the unqualified references to Range and Cells means
that it works only with data on the active sheet.

It can be generalized even further. Suppose the X and Y data are
demarcated by empty cells around them. In other words the col. to the
right of the X data is empty, followed by the Y data followed by at
least one empty column. In addition, the row below the data set is
also empty. Then, the code below will work:

Sub testIt2()
Dim X As Variant, Y As Variant, Rslt As Variant
X = Cells(1, 1).CurrentRegion.Value
Y = Cells(1, 1).End(xlToRight).End(xlToRight).CurrentRegion.Val ue
Rslt = Application.WorksheetFunction.LinEst(Y, X, True, True)
Cells(Rows.Count, 1).End(xlUp).Offset(2, 0) _
.Resize(5, UBound(Rslt, 2) - LBound(Rslt, 2) + 1) = Rslt
End Sub

It handles any number of independent variables and any number of data
points!