Examples - pi.science.regression.PIPowerRegression
1. How to compute power regression for X and Y values ?
/* change decimal places count in formulas */ PIConfiguration.REGRESSION_DECIMAL_PLACES = 6; /* - prepare X data for regression */ PIVariable X = new PIVariable(); X.AddValues( new double[] { 17.6, 26.0, 31.9, 38.9, 45.8 } ); X.AddValues( new double[] { 51.2, 58.1, 64.7, 66.7, 80.8, 82.9 } ); /* - prepare Y data for regression */ PIVariable Y = new PIVariable(); Y.AddValues( new double[] { 159.9, 206.9, 236.8, 269.9, 300.6 } ); Y.AddValues( new double[] { 323.6, 351.7, 377.6, 384.1, 437.2, 444.7 } ); /* - create and compute regression */ PIPowerRegression regression = new PIPowerRegression( X, Y ); regression.Calc(); Console.WriteLine( regression.GetTextFormula() ); Console.WriteLine( regression.GetTextFormulaFilled() ); /* - calc prediction for X = 3.5 */ PIDebug.Blank(); Console.WriteLine( "Prediction for X=40 : " + regression.CalcPredictedY( 40.0 ) ); PIDebug.Blank(); Console.WriteLine( "Prediction errors:" ); Console.WriteLine( regression.GetErrors().AsString( 5 ) ); PIDebug.Blank(); Console.WriteLine( "R2 = " + regression.GetR2() );
Output:
y = A * x^B y = 24.129893 * x ^0.659498 Prediction for X=40 : 274.85932141715045 Prediction errors: -0.04412;0.01584;0.04341;0.04921;0.06673;0.14400;0.11875;0.16443;-0.99015;0.19236;0.23463 R2 = 0.9947870030308327