# R2 (coefficient of determination) from Forecasting?

### Question

• how can you get R2 from the Forecasting calculation? (http://en.wikipedia.org/wiki/Linear_regression#Analysis_of_variance)

Chart1.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, parameters, "Input:Y", "Forecasting:Y,Range:Y,Range:Y2");

i found out that you could do
var R = Chart1.DataManipulator.Statistics.Correlation("Input", "Forecasting");
var R2 = R*R;

but only with only if you got the same number of points in Inputs as the Forecasting result array.

R2 is defined as R2 = 1- (SSerr/ SStot), and most often also R2 = SSreg / SStot (http://en.wikipedia.org/wiki/Coefficient_of_determination)

SStot can you get from Chart1.DataManipulator.Statistics.Anova(0.8, "Input").SumOfSquaresTotal but what about SSreg or SSerr?

also, how do you easiest get the K and M coefficients (y = kx+m) from the forecasting line? M should be Chart1.Series["Forecasting"].Points[0].YValues[0], but K?
Friday, November 28, 2008 10:41 PM

• Forecasting formula supports 4 optional parameters:

1. Polynomial regression of the specified degree or predefined regression type "Exponential, Logarithmic or Power". Default "2"
2. Forecasting period. Default half of the series length.
3. Returns Approximation error. Default is true;
4. Returns Forecasting error. Default is true.

Here is an example:

 FormulaFinancial(FinancialFormula.Forecasting,"2,40,true,true", "Series1:Y","Series2:Y,Series3:Y,Series3:Y2")

All other features are not supported and can be implemented from scratch after chart is bound to the data.

Alex.

Tuesday, December 02, 2008 10:50 PM
• Our main goal was to add formulas, so that they can be rendered in the chart. We do not provide access to any intermediate results. I suggest you search in the internet the code for solving this equation.

ALex.
http://blogs.msdn.com/alexgor
Friday, February 13, 2009 4:39 PM

### All replies

• Forecasting formula supports 4 optional parameters:

1. Polynomial regression of the specified degree or predefined regression type "Exponential, Logarithmic or Power". Default "2"
2. Forecasting period. Default half of the series length.
3. Returns Approximation error. Default is true;
4. Returns Forecasting error. Default is true.

Here is an example:

 FormulaFinancial(FinancialFormula.Forecasting,"2,40,true,true", "Series1:Y","Series2:Y,Series3:Y,Series3:Y2")

All other features are not supported and can be implemented from scratch after chart is bound to the data.

Alex.

Tuesday, December 02, 2008 10:50 PM
• Hi Alex,

I'm interested in using the Polynomial regression (don't even care to actually display the chart, other than for debugging and sanity check) but I need to pull out the coefficients of a 3rd order equation (y = a + bx + cx^2 + dx^3).  I have displayed the chart and it seems to be correctly calculating this equation.  It puts the y values in a new series, but I don't care about that as much as I care about finding the {a, b, c, d.

Is there any way to do this with the existing classes?

Does MS plan to add this functionality?

It seems such a waste that they are doing all the heavy lifting of calculating this formula but they just don't add a few accessors after the fact ???
Friday, February 13, 2009 3:27 PM
• Our main goal was to add formulas, so that they can be rendered in the chart. We do not provide access to any intermediate results. I suggest you search in the internet the code for solving this equation.

ALex.
http://blogs.msdn.com/alexgor
Friday, February 13, 2009 4:39 PM
• Hi Carl,

I came across your post from a couple of years ago because I was trying to do the same thing.  It turns out that calculating the regression formula (and optionally a predicted value for Y=f(x) is pretty simple for linear regression, just calculate deltaX and deltaY for two points along the plotted regression line, calculate the X offset to the Y-intercept, and you have the formula.

You probably already figured out that Chart1.Series["Forecasting"].Points[0].YValues[0] only derives the Y-intercept if XValue[0]=0.  Otherwise you need to calculate the offset to X=0.

-BGood
Tuesday, December 07, 2010 9:23 PM