View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis Dana DeLouis is offline
external usenet poster
 
Posts: 947
Default Custom function for max residual from linear regression

... The Analysis ToolPak-VBA seems
promising for a template, but it is password protected-any potential
for accessing this?


Hi. Not sure what you mean for "accessing" the ATP, so I'll just throw
this out as an idea.
As a small example, the ATP function "LCM" is not available to vba.
However, in the vba editor, go to Tools | References...and select
"atpvbaen.xls"
Now you can run ATP codes like the following simple example:

Sub Demo()
MsgBox LCM(3, 5)
End Sub

To see what's available in the vba editor, pull up the vba editor, and
open the object browser (F2). Then, pull up just the atpvbaen.xls
library from the upper left corner.

HTH
Dana DeLouis



Bob Nelson wrote:
Hi Richard,

Elegant solution! Many thanks! I had been trying to go work out a
tenable loop, but was having trouble with the syntax and had not
considered using the built-in functions in VBA to get me to the
residuals.

By the way, this is my first foray into a usenet group and I am in awe
of the helpfulness and willingness to field questions from complete
strangers. I look forward to gathering enough expertise so that I can
"pay it forward".

Thanks again for saving me many hours of headscratching and best of
luck with your own adventures with Excel.

Cheers,
Bob

wrote:
Hi Bob.

I would suggest the following:
1) Obtain the slope & intercept from LINEST (or SLOPE and INTERCEPT)
using your code
2) Calculate the maximum residual for each datapoint using code
eg
for i = 1 to N
residual = yvalue(i) - (intercept + slope * xvalue(i))
' or residual = abs(yvalue(i) - (intercept + slope *
xvalue(i)))
if residual maxresidual then maxresidual = residual
next i

This should be pretty fast so long as you don't have too many
datapoints.

Cheers
Richard

Bob Nelson wrote:
Greetings, I'm trying to write a custom worksheet function in Excel
2003 that will return the maximum residual value from a linear
regression. Unfortunately, this is not one of the potential outputs
from LINEST. I realize the Analysis ToolPak regression option will
generate a list of residuals from which a maximum value could be
extracted, but this requires generating a new worksheet or large array,
and I'm working with a dynamic array on a worksheet from which the
maximum residual will need to be "updated" in each row of a column.


The SLOPE and INTERCEPT built-in functions perform analogous tasks
(i.e. linear regressions are calculated before specific parameters of
the line generated are returned) but my understanding is that VBA
source code for these is not available? The Analysis ToolPak-VBA seems
promising for a template, but it is password protected-any potential
for accessing this?

So...any thoughts or directions on where to take this? Thanks in
advance for your suggestions.

Bob Nelson