T
tkpmep
I created a UDF to perform a regression on two ranges, X and Y that
reliably hangs Excel 2003 and 2007: both ranges are copied into arrays
of length N, and I create an array of intermediate results of length
N*(N-1)/2 as follows
Public Function TheilSenRegression(x As Range, y As Range)
Dim xx() As Double, yy() As Double, slopes() As Double
'compute N and Nc2 = N(N-1)/2
ReDim xx(1 to N) as double 'copy x into xx
ReDim yy(1 to N) as double 'copy y into yy
ReDim slopes(1 to Nc2) as double 'copy intermediate results into
slopes
..
..
TheilSenSlope = Application.WorksheetFunction.Median(slopes)
TheilSenRegression = Array(TheilSenSlope, TheilSenIntercept)
End Function
The function works like a charm when I call it less than about 10
times in a spreadsheet - X and Y are of length 100, so that nC2 is
just under 5000. Call it more often and Excel hangs reliably. My gut
instinct is that Excel gets into trouble allocating memory for the
array slope() or that calling Median causes a problem, but have no
thoughts on how to fix it. Any insights would be greatly appreciated
Sincerely
Thomas Philips
reliably hangs Excel 2003 and 2007: both ranges are copied into arrays
of length N, and I create an array of intermediate results of length
N*(N-1)/2 as follows
Public Function TheilSenRegression(x As Range, y As Range)
Dim xx() As Double, yy() As Double, slopes() As Double
'compute N and Nc2 = N(N-1)/2
ReDim xx(1 to N) as double 'copy x into xx
ReDim yy(1 to N) as double 'copy y into yy
ReDim slopes(1 to Nc2) as double 'copy intermediate results into
slopes
..
..
TheilSenSlope = Application.WorksheetFunction.Median(slopes)
TheilSenRegression = Array(TheilSenSlope, TheilSenIntercept)
End Function
The function works like a charm when I call it less than about 10
times in a spreadsheet - X and Y are of length 100, so that nC2 is
just under 5000. Call it more often and Excel hangs reliably. My gut
instinct is that Excel gets into trouble allocating memory for the
array slope() or that calling Median causes a problem, but have no
thoughts on how to fix it. Any insights would be greatly appreciated
Sincerely
Thomas Philips