Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Custom function for max residual from linear regression

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Custom function for max residual from linear regression

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Custom function for max residual from linear regression

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Custom function for max residual from linear regression

Thanks for your message, Dana. I'm unable to view the VBA code for
atpvbaen.xls, though I can see the description for the "Regress"
subroutine in the object browser. The View | Code option is greyed out.
I'm presuming I need to be recognized as a developer (which I am not)
to gain access to the code.

Thanks again,
Bob

Dana DeLouis wrote:
... 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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 837
Default Custom function for max residual from linear regression

The maximum absolute residual can be computed by the array formula
=MAX(ABS(ydata-TREND(ydata,xdata,xdata)))
This has the same capability for multi-linear regression as LINEST (which is
the calculation engine for the ATP regression tool). In VBA, you can use
Application.Evaluate to get array evaluation of worksheet functions.

Jerry

"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


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Custom function for max residual from linear regression

Jerry,

Great solution! This eliminated the need for VBA in my case. With one
extra column in the worksheet, I was able to track when a new starting
row was signaled for the dynamic arrays (used to generate a line), then
use OFFSET in combination with TREND to return max (and min) residuals
using your formula.

Thanks again for the collective wisdom of the group in your solutions
to this question!

Bob

Jerry W. Lewis wrote:
The maximum absolute residual can be computed by the array formula
=MAX(ABS(ydata-TREND(ydata,xdata,xdata)))
This has the same capability for multi-linear regression as LINEST (which is
the calculation engine for the ATP regression tool). In VBA, you can use
Application.Evaluate to get array evaluation of worksheet functions.

Jerry

"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



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 837
Default Custom function for max residual from linear regression

You're welcome. Glad it helped.

Jerry

"Bob Nelson" wrote:

Jerry,

Great solution! This eliminated the need for VBA in my case. With one
extra column in the worksheet, I was able to track when a new starting
row was signaled for the dynamic arrays (used to generate a line), then
use OFFSET in combination with TREND to return max (and min) residuals
using your formula.

Thanks again for the collective wisdom of the group in your solutions
to this question!

Bob

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
residual plots in multiple regression rjh Excel Worksheet Functions 1 August 23rd 09 01:38 AM
Linear Regression al boccia Excel Worksheet Functions 8 December 12th 08 09:40 PM
The multiple regression tool - linear or non-linear regression? Statistical interest Excel Discussion (Misc queries) 2 February 6th 08 11:01 PM
Regression Residual Plots Andrew Excel Discussion (Misc queries) 0 July 6th 07 08:14 AM
Linear Regression using the TREND function scarlett1 Excel Worksheet Functions 2 May 26th 06 03:04 PM


All times are GMT +1. The time now is 12:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"