PC Review


Reply
Thread Tools Rate Thread

Error When Trying to Calculate R Squared With Only One Datapoint

 
 
=?Utf-8?B?TWlrZSBD?=
Guest
Posts: n/a
 
      20th Feb 2007
I have code (exerpt below) that loops through a recordset, adds a trendline
to a graph, and puts the R Squared value in a table. The problem is that some
of the graphs only have one datapoint i.e. no trendline, so it throws an
error that says "unable to set the displayrsquared property of the trendline
class". I tried to count the datapoints in the series collection first and
only add a trendline if the number of datapoints is greater than 1 but it
doesn't seem to work. Any thoughts? Thanks!!!

MarketShareProductIMS3Dollar.SeriesCollection

If MarketShareProductIMS3Dollar.SeriesCollection(1).Points.Count > 1 Then

Set mySheet = MarketShareProductIMS3Dollar.Application.DataSheet

Company = mySheet.Cells(1, i + 1)
With MarketShareProductIMS3Dollar.SeriesCollection(1)

.Trendlines.ADD Type:=xlLinear, Name:=Company & " Linear
Trend"
.Trendlines(1).DisplayRSquared = True
End If
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QWxsZW5fTg==?=
Guest
Posts: n/a
 
      20th Feb 2007
Just a guess, but you might have to restrict to data sets with > 2 points. A
trendline fitted to 2 points will have a zero 'sum of squares of residuals',
which might cause a divide-by-zero somewhere.

"Mike C" wrote:

> I have code (exerpt below) that loops through a recordset, adds a trendline
> to a graph, and puts the R Squared value in a table. The problem is that some
> of the graphs only have one datapoint i.e. no trendline, so it throws an
> error that says "unable to set the displayrsquared property of the trendline
> class". I tried to count the datapoints in the series collection first and
> only add a trendline if the number of datapoints is greater than 1 but it
> doesn't seem to work. Any thoughts? Thanks!!!
>
> MarketShareProductIMS3Dollar.SeriesCollection
>
> If MarketShareProductIMS3Dollar.SeriesCollection(1).Points.Count > 1 Then
>
> Set mySheet = MarketShareProductIMS3Dollar.Application.DataSheet
>
> Company = mySheet.Cells(1, i + 1)
> With MarketShareProductIMS3Dollar.SeriesCollection(1)
>
> .Trendlines.ADD Type:=xlLinear, Name:=Company & " Linear
> Trend"
> .Trendlines(1).DisplayRSquared = True
> End If

 
Reply With Quote
 
=?Utf-8?B?TWlrZSBD?=
Guest
Posts: n/a
 
      20th Feb 2007
That was the purpose of the line that reads:

If MarketShareProductIMS3Dollar.SeriesCollection(1).Points.Count > 1 Then

"Allen_N" wrote:

> Just a guess, but you might have to restrict to data sets with > 2 points. A
> trendline fitted to 2 points will have a zero 'sum of squares of residuals',
> which might cause a divide-by-zero somewhere.
>
> "Mike C" wrote:
>
> > I have code (exerpt below) that loops through a recordset, adds a trendline
> > to a graph, and puts the R Squared value in a table. The problem is that some
> > of the graphs only have one datapoint i.e. no trendline, so it throws an
> > error that says "unable to set the displayrsquared property of the trendline
> > class". I tried to count the datapoints in the series collection first and
> > only add a trendline if the number of datapoints is greater than 1 but it
> > doesn't seem to work. Any thoughts? Thanks!!!
> >
> > MarketShareProductIMS3Dollar.SeriesCollection
> >
> > If MarketShareProductIMS3Dollar.SeriesCollection(1).Points.Count > 1 Then
> >
> > Set mySheet = MarketShareProductIMS3Dollar.Application.DataSheet
> >
> > Company = mySheet.Cells(1, i + 1)
> > With MarketShareProductIMS3Dollar.SeriesCollection(1)
> >
> > .Trendlines.ADD Type:=xlLinear, Name:=Company & " Linear
> > Trend"
> > .Trendlines(1).DisplayRSquared = True
> > End If

 
Reply With Quote
 
=?Utf-8?B?TWlrZSBD?=
Guest
Posts: n/a
 
      20th Feb 2007
Now I see what you're saying, Allen. Thank you for the suggestion but that
did not work either.

"Allen_N" wrote:

> Just a guess, but you might have to restrict to data sets with > 2 points. A
> trendline fitted to 2 points will have a zero 'sum of squares of residuals',
> which might cause a divide-by-zero somewhere.
>
> "Mike C" wrote:
>
> > I have code (exerpt below) that loops through a recordset, adds a trendline
> > to a graph, and puts the R Squared value in a table. The problem is that some
> > of the graphs only have one datapoint i.e. no trendline, so it throws an
> > error that says "unable to set the displayrsquared property of the trendline
> > class". I tried to count the datapoints in the series collection first and
> > only add a trendline if the number of datapoints is greater than 1 but it
> > doesn't seem to work. Any thoughts? Thanks!!!
> >
> > MarketShareProductIMS3Dollar.SeriesCollection
> >
> > If MarketShareProductIMS3Dollar.SeriesCollection(1).Points.Count > 1 Then
> >
> > Set mySheet = MarketShareProductIMS3Dollar.Application.DataSheet
> >
> > Company = mySheet.Cells(1, i + 1)
> > With MarketShareProductIMS3Dollar.SeriesCollection(1)
> >
> > .Trendlines.ADD Type:=xlLinear, Name:=Company & " Linear
> > Trend"
> > .Trendlines(1).DisplayRSquared = True
> > End If

 
Reply With Quote
 
=?Utf-8?B?TWlrZSBD?=
Guest
Posts: n/a
 
      21st Feb 2007
all set. the problem was with null values in my recordset not with the code
itself per say. thanks.

"Mike C" wrote:

> I have code (exerpt below) that loops through a recordset, adds a trendline
> to a graph, and puts the R Squared value in a table. The problem is that some
> of the graphs only have one datapoint i.e. no trendline, so it throws an
> error that says "unable to set the displayrsquared property of the trendline
> class". I tried to count the datapoints in the series collection first and
> only add a trendline if the number of datapoints is greater than 1 but it
> doesn't seem to work. Any thoughts? Thanks!!!
>
> MarketShareProductIMS3Dollar.SeriesCollection
>
> If MarketShareProductIMS3Dollar.SeriesCollection(1).Points.Count > 1 Then
>
> Set mySheet = MarketShareProductIMS3Dollar.Application.DataSheet
>
> Company = mySheet.Cells(1, i + 1)
> With MarketShareProductIMS3Dollar.SeriesCollection(1)
>
> .Trendlines.ADD Type:=xlLinear, Name:=Company & " Linear
> Trend"
> .Trendlines(1).DisplayRSquared = True
> End If

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel error in R-squared computation in exponential regression =?Utf-8?B?QmpvZXJu?= Microsoft Excel Misc 7 28th Oct 2007 03:17 AM
How do you type something squared, like centimeters squared? =?Utf-8?B?UmFjaGVsODc=?= Microsoft Word Document Management 1 10th Oct 2005 03:13 AM
a-squared error windows 98SE ALPI Freeware 1 26th Dec 2004 04:33 PM
Datapoint position Holger Gerths Microsoft Excel Charting 7 23rd Apr 2004 05:26 PM
Recognize a chart-datapoint for use in vba hglamy Microsoft Excel Charting 4 24th Nov 2003 08:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:24 AM.