<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, How to calculate coefficient of determination of a nonlinear fit</title>
    <link>http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Fri, 12 Jun 2026 19:14:24 GMT</lastBuildDate>
    <pubDate>Fri, 12 Jun 2026 19:14:24 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, How to calculate coefficient of determination of a nonlinear fit</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, How to calculate coefficient of determination of a nonlinear fit</title>
      <link>http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination</link>
    </image>
    <item>
      <title>Best solution is by transforming to a linear fit</title>
      <link>http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination?ref=Feed:MaplePrimes:How to calculate coefficient of determination of a nonlinear fit:Comments#answer120021</link>
      <itunes:summary>&lt;p&gt;Hi Andreas,&lt;/p&gt;
&lt;p&gt;I entered the data in your example; this looks like data that would be good to fit with an exponential function. (The Excel notation is a little puzzling, but it seems that that's what happens there too.) An exponential function is of course nonlinear, but the fitting process itself is linear: you take the logarithms of all the observations, do a linear fit, and then apply &lt;em&gt;exp&lt;/em&gt; to the result. Maple supports this using the &lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=Statistics/ExponentialFit"&gt;?Statistics/ExponentialFit&lt;/a&gt; command:&lt;/p&gt;
&lt;pre&gt;with(Statistics):&lt;br&gt;data := &amp;lt;0.07, 2,0.16, 0.24, 0.36, 0.5, 0.8, 1.2, 1.8, 8, 4, 6, 9, 15, 20, 30, 43, 66.9, 100, 150&amp;gt;;&lt;br&gt;PointPlot(data, axis[2]=[mode=log]); # to show that an exponential fit will work&lt;br&gt;result := ExponentialFit(&amp;lt;seq(1 .. 20)&amp;gt;, data, x);&lt;/pre&gt;
&lt;p style="text-align: center;"&gt;&amp;nbsp;&lt;img class="plot" src="http://www.mapleprimes.com/MapleImage.ashx?f=2a95d369bde6e2ac37cdb867d640ad2a.gif" alt="PLOT(CURVES([[1., 0.7e-1], [2., 2.], [3., .16], [4., .24], [5., .36], [6., .5], [7., .8], [8., 1.2], [9., 1.8], [10., 8.], [11., 4.], [12., 6.], [13., 9.], [14., 15.], [15., 20.], [16., 30.], [17., 43.], [18., 66.9], [19., 100.], [20., 150.]], COLOUR(HSV, .5476190475, 1.000000000, .7000000000), LEGEND(&amp;quot;__never_display_this_legend_entry&amp;quot;)), STYLE(POINT), _AXIS[2](_MODE(1)))"&gt;&lt;/p&gt;
&lt;p style="text-align: left;"&gt;This assigns &lt;em&gt;result&lt;/em&gt; := 0.0866208931860853*exp(0.365097831283158*&lt;em&gt;x&lt;/em&gt;). In order to find the &lt;em&gt;R&lt;/em&gt;^2 value for this (linear!) fit, we need the residual sum of squares (easy to obtain with ExponentialFit) and the so-called total corrected sum of squares. For this total corrected sum of squares, we can't use ExponentialFit and we'll need to do the transformation by hand. We can obtain the total sum of squares by seeing that the second central moment is the &lt;em&gt;average&lt;/em&gt; of the squared deviations from the mean, whereas the total sum of squares is the &lt;em&gt;sum&lt;/em&gt; of the squared deviations from the mean - thus they differ by the factor given by the number of data points. Putting this together, we obtain:&lt;/p&gt;
&lt;pre style="text-align: left;"&gt;ssRes := Statistics:-ExponentialFit(&amp;lt;seq(1..20)&amp;gt;, data, x, 'output = residualsumofsquares');&lt;br&gt;logdata := log~(data);&lt;br&gt;ssTotal := numelems(logdata) * CentralMoment(logdata, 2);&lt;br&gt;Rsquared := 1 - ssRes / ssTotal;&lt;/pre&gt;
&lt;p style="text-align: left;"&gt;This results in a value of 0.9167199079, which is what Excel also seems to get.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;If you have a more esoteric fitting function and you need to use &lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=Statistics/NonlinearFit"&gt;?Statistics/NonlinearFit&lt;/a&gt; or, better, &lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=Statistics/Fit"&gt;?Statistics/Fit&lt;/a&gt;, you can use the same approach to find the pseudo-R^2, except you would take the central moment of &lt;em&gt;data&lt;/em&gt; - since there is not necessarily an equivalent of &lt;em&gt;logdata&lt;/em&gt; that makes sense in that case.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;Hope this helps,&lt;/p&gt;
&lt;p style="text-align: left;"&gt;Erik Postma&lt;br&gt;Maplesoft.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Hi Andreas,&lt;/p&gt;
&lt;p&gt;I entered the data in your example; this looks like data that would be good to fit with an exponential function. (The Excel notation is a little puzzling, but it seems that that's what happens there too.) An exponential function is of course nonlinear, but the fitting process itself is linear: you take the logarithms of all the observations, do a linear fit, and then apply &lt;em&gt;exp&lt;/em&gt; to the result. Maple supports this using the &lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=Statistics/ExponentialFit"&gt;?Statistics/ExponentialFit&lt;/a&gt; command:&lt;/p&gt;
&lt;pre&gt;with(Statistics):&lt;br&gt;data := &amp;lt;0.07, 2,0.16, 0.24, 0.36, 0.5, 0.8, 1.2, 1.8, 8, 4, 6, 9, 15, 20, 30, 43, 66.9, 100, 150&amp;gt;;&lt;br&gt;PointPlot(data, axis[2]=[mode=log]); # to show that an exponential fit will work&lt;br&gt;result := ExponentialFit(&amp;lt;seq(1 .. 20)&amp;gt;, data, x);&lt;/pre&gt;
&lt;p style="text-align: center;"&gt;&amp;nbsp;&lt;img class="plot" src="http://www.mapleprimes.com/MapleImage.ashx?f=2a95d369bde6e2ac37cdb867d640ad2a.gif" alt="PLOT(CURVES([[1., 0.7e-1], [2., 2.], [3., .16], [4., .24], [5., .36], [6., .5], [7., .8], [8., 1.2], [9., 1.8], [10., 8.], [11., 4.], [12., 6.], [13., 9.], [14., 15.], [15., 20.], [16., 30.], [17., 43.], [18., 66.9], [19., 100.], [20., 150.]], COLOUR(HSV, .5476190475, 1.000000000, .7000000000), LEGEND(&amp;quot;__never_display_this_legend_entry&amp;quot;)), STYLE(POINT), _AXIS[2](_MODE(1)))"&gt;&lt;/p&gt;
&lt;p style="text-align: left;"&gt;This assigns &lt;em&gt;result&lt;/em&gt; := 0.0866208931860853*exp(0.365097831283158*&lt;em&gt;x&lt;/em&gt;). In order to find the &lt;em&gt;R&lt;/em&gt;^2 value for this (linear!) fit, we need the residual sum of squares (easy to obtain with ExponentialFit) and the so-called total corrected sum of squares. For this total corrected sum of squares, we can't use ExponentialFit and we'll need to do the transformation by hand. We can obtain the total sum of squares by seeing that the second central moment is the &lt;em&gt;average&lt;/em&gt; of the squared deviations from the mean, whereas the total sum of squares is the &lt;em&gt;sum&lt;/em&gt; of the squared deviations from the mean - thus they differ by the factor given by the number of data points. Putting this together, we obtain:&lt;/p&gt;
&lt;pre style="text-align: left;"&gt;ssRes := Statistics:-ExponentialFit(&amp;lt;seq(1..20)&amp;gt;, data, x, 'output = residualsumofsquares');&lt;br&gt;logdata := log~(data);&lt;br&gt;ssTotal := numelems(logdata) * CentralMoment(logdata, 2);&lt;br&gt;Rsquared := 1 - ssRes / ssTotal;&lt;/pre&gt;
&lt;p style="text-align: left;"&gt;This results in a value of 0.9167199079, which is what Excel also seems to get.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;If you have a more esoteric fitting function and you need to use &lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=Statistics/NonlinearFit"&gt;?Statistics/NonlinearFit&lt;/a&gt; or, better, &lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=Statistics/Fit"&gt;?Statistics/Fit&lt;/a&gt;, you can use the same approach to find the pseudo-R^2, except you would take the central moment of &lt;em&gt;data&lt;/em&gt; - since there is not necessarily an equivalent of &lt;em&gt;logdata&lt;/em&gt; that makes sense in that case.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;Hope this helps,&lt;/p&gt;
&lt;p style="text-align: left;"&gt;Erik Postma&lt;br&gt;Maplesoft.&lt;/p&gt;</description>
      <guid>120021</guid>
      <pubDate>Thu, 19 May 2011 00:13:03 Z</pubDate>
      <itunes:author>epostma</itunes:author>
      <author>epostma</author>
    </item>
    <item>
      <title>How to calc residualsumofsquares</title>
      <link>http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination?ref=Feed:MaplePrimes:How to calculate coefficient of determination of a nonlinear fit:Comments#comment120059</link>
      <itunes:summary>&lt;p class="p1"&gt;&lt;span class="s1"&gt;Thanks&amp;nbsp;Erik&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;Just to make sure that I understand this:&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;When I want to fit on a exponential function I should perform a log on my Y data, as use did&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;When it is a power function I should also perform a log on my Y data:&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;X := &amp;lt;seq(i, i = 1 .. 20)&amp;gt;;&lt;br&gt; Y := &amp;lt;2.6, 3, 3.6, 4, 4.5, 5, 5.7, 6, 6.7, 7, 7.8, 8, 8.5, 9, 9.6, 10.1, 10.6, 11, 12, 12.4)&amp;gt;;&lt;br&gt; ssRes := PowerFit(X, Y, x, output = 'residualsumofsquares');&lt;br&gt; Y := log~(Y);&lt;br&gt; ssTotal := ArrayTools:-NumElems(Y)*CentralMoment(Y, 2);&lt;br&gt; R^2 = 1-ssRes/ssTotal; #0.9627722617&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;But in any other case the Y data shouldn't be modified:&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;X := &amp;lt;seq(10*i, i = 0 .. 18)&amp;gt;;&lt;br&gt; Y := &amp;lt;0, .4, .8, 1.9, 4, 7.1, 10.1, 14.6, 15.9, 12.3, 11.5, 9.4, 6.1, 2.6, 1.6, .8, .2, 0, 0&amp;gt;;&lt;br&gt; f := (x) -&amp;gt; a*sin((1/180)*x*Pi)^n;&lt;br&gt; ssRes := Fit(f(x), X, Y, x, output = 'residualsumofsquares');&lt;br&gt; ssTotal := ArrayTools:-NumElems(Y)*CentralMoment(Y, 2);&lt;br&gt; R^2 = 1-ssRes/ssTotal; #0.9062393748&lt;/span&gt;&lt;/p&gt;
&lt;p class="p2"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="p2"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;Also how dose maple calculate the residual sum of squares. I'm interested in this because I not always want to make a fit&lt;br&gt; but just want to compare the results to an already know function.&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;I have tryed with this: &amp;nbsp;&lt;br&gt; residualsumofsquares := proc (f, X, Y, T)&lt;br&gt; &amp;nbsp; &amp;nbsp;local N;&lt;br&gt; &amp;nbsp; &amp;nbsp;N := ArrayTools:-NumElems(Y);&lt;br&gt; &amp;nbsp; &amp;nbsp;return add((Y[i]-(eval(f, T = X[i])))^2, i = 1 .. N)&lt;br&gt; end proc;&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;But it dosn't work when it is a&amp;nbsp;exponential or power function:&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;X := &amp;lt;seq(i, i = 1 .. 20)&amp;gt;;&lt;br&gt; Y := &amp;lt;0.07, 2, .16, .24, .36, .5, .8, 1.2, 1.8, 8, 4, 6, 9, 15, 20, 30, 43, 66.9, 100, 150&amp;gt;;&lt;br&gt; ssRes := ExponentialFit(X, Y, x, output = 'residualsumofsquares'); #8.05275870047944231&lt;br&gt; fitFn := ExponentialFit(X, Y, x);&lt;br&gt; residualsumofsquares(fitFn, X, Y, x); #634.4706207160136 &amp;ndash; should be ssRes&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;The question is:&lt;br&gt; &amp;ndash; are I'm correct when I say the log~(Y) only should be used when it is an exponential or power function?&lt;br&gt; &amp;ndash; how to calculate the residual sum of squares when it is a&amp;nbsp;exponential or power function?&lt;/span&gt;&lt;/p&gt;
&lt;p class="p2"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</itunes:summary>
      <description>&lt;p class="p1"&gt;&lt;span class="s1"&gt;Thanks&amp;nbsp;Erik&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;Just to make sure that I understand this:&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;When I want to fit on a exponential function I should perform a log on my Y data, as use did&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;When it is a power function I should also perform a log on my Y data:&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;X := &amp;lt;seq(i, i = 1 .. 20)&amp;gt;;&lt;br&gt; Y := &amp;lt;2.6, 3, 3.6, 4, 4.5, 5, 5.7, 6, 6.7, 7, 7.8, 8, 8.5, 9, 9.6, 10.1, 10.6, 11, 12, 12.4)&amp;gt;;&lt;br&gt; ssRes := PowerFit(X, Y, x, output = 'residualsumofsquares');&lt;br&gt; Y := log~(Y);&lt;br&gt; ssTotal := ArrayTools:-NumElems(Y)*CentralMoment(Y, 2);&lt;br&gt; R^2 = 1-ssRes/ssTotal; #0.9627722617&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;But in any other case the Y data shouldn't be modified:&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;X := &amp;lt;seq(10*i, i = 0 .. 18)&amp;gt;;&lt;br&gt; Y := &amp;lt;0, .4, .8, 1.9, 4, 7.1, 10.1, 14.6, 15.9, 12.3, 11.5, 9.4, 6.1, 2.6, 1.6, .8, .2, 0, 0&amp;gt;;&lt;br&gt; f := (x) -&amp;gt; a*sin((1/180)*x*Pi)^n;&lt;br&gt; ssRes := Fit(f(x), X, Y, x, output = 'residualsumofsquares');&lt;br&gt; ssTotal := ArrayTools:-NumElems(Y)*CentralMoment(Y, 2);&lt;br&gt; R^2 = 1-ssRes/ssTotal; #0.9062393748&lt;/span&gt;&lt;/p&gt;
&lt;p class="p2"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="p2"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;Also how dose maple calculate the residual sum of squares. I'm interested in this because I not always want to make a fit&lt;br&gt; but just want to compare the results to an already know function.&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;I have tryed with this: &amp;nbsp;&lt;br&gt; residualsumofsquares := proc (f, X, Y, T)&lt;br&gt; &amp;nbsp; &amp;nbsp;local N;&lt;br&gt; &amp;nbsp; &amp;nbsp;N := ArrayTools:-NumElems(Y);&lt;br&gt; &amp;nbsp; &amp;nbsp;return add((Y[i]-(eval(f, T = X[i])))^2, i = 1 .. N)&lt;br&gt; end proc;&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;But it dosn't work when it is a&amp;nbsp;exponential or power function:&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;X := &amp;lt;seq(i, i = 1 .. 20)&amp;gt;;&lt;br&gt; Y := &amp;lt;0.07, 2, .16, .24, .36, .5, .8, 1.2, 1.8, 8, 4, 6, 9, 15, 20, 30, 43, 66.9, 100, 150&amp;gt;;&lt;br&gt; ssRes := ExponentialFit(X, Y, x, output = 'residualsumofsquares'); #8.05275870047944231&lt;br&gt; fitFn := ExponentialFit(X, Y, x);&lt;br&gt; residualsumofsquares(fitFn, X, Y, x); #634.4706207160136 &amp;ndash; should be ssRes&lt;/span&gt;&lt;/p&gt;
&lt;p class="p1"&gt;&lt;span class="s1"&gt;The question is:&lt;br&gt; &amp;ndash; are I'm correct when I say the log~(Y) only should be used when it is an exponential or power function?&lt;br&gt; &amp;ndash; how to calculate the residual sum of squares when it is a&amp;nbsp;exponential or power function?&lt;/span&gt;&lt;/p&gt;
&lt;p class="p2"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
      <guid>120059</guid>
      <pubDate>Thu, 19 May 2011 22:25:06 Z</pubDate>
      <itunes:author>Andreas Madsen</itunes:author>
      <author>Andreas Madsen</author>
    </item>
    <item>
      <title>ln</title>
      <link>http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination?ref=Feed:MaplePrimes:How to calculate coefficient of determination of a nonlinear fit:Comments#comment120064</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination#comment120059"&gt;@Andreas Madsen&lt;/a&gt; In your `residualsumofsquares` procedure, try,&lt;/p&gt;
&lt;pre&gt;  add(evalf((ln(Y[i])-ln(eval(f, T = X[i])))^2), i = 1 .. N);
&lt;/pre&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination#comment120059"&gt;@Andreas Madsen&lt;/a&gt; In your `residualsumofsquares` procedure, try,&lt;/p&gt;
&lt;pre&gt;  add(evalf((ln(Y[i])-ln(eval(f, T = X[i])))^2), i = 1 .. N);
&lt;/pre&gt;</description>
      <guid>120064</guid>
      <pubDate>Thu, 19 May 2011 23:45:49 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>Answers</title>
      <link>http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination?ref=Feed:MaplePrimes:How to calculate coefficient of determination of a nonlinear fit:Comments#comment120066</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination#comment120059"&gt;@Andreas Madsen&lt;/a&gt; : Well, there really is no difference between an exponential function and a power function, right? The equations &lt;em&gt;y&lt;/em&gt; = &lt;em&gt;a&lt;/em&gt; * &lt;em&gt;b&lt;/em&gt;^&lt;em&gt;x&lt;/em&gt; and &lt;em&gt;y&lt;/em&gt; = &lt;em&gt;a&lt;/em&gt; * exp(&lt;em&gt;B * x)&lt;/em&gt; and &lt;em&gt;y&lt;/em&gt; = exp(&lt;em&gt;A&lt;/em&gt; + &lt;em&gt;B&lt;/em&gt; * &lt;em&gt;x&lt;/em&gt;) are all equivalent, if &lt;em&gt;A&lt;/em&gt; = exp(&lt;em&gt;a&lt;/em&gt;) and &lt;em&gt;B&lt;/em&gt; = exp(&lt;em&gt;b&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;The nice thing about doing the log transform is that that turns it into a linear fitting problem. (Both the exponential and the power fit, since they are the same.) That means that we can discuss the transformed, linear, fitting problem instead of the original nonlinear one. A perfect fit for one problem clearly translates into a perfect fit for the other; we sort of assume that a good-but-not-perfect fit for the one will still translate into a good fit for the other (and actually, the measure of fit may be better in this case than in the original, as a friend recently pointed out to me). For the linear problem, we can talk about R^2, defined in terms of the residual sum of squares and total sum of squares in the log-transformed problem; for the nonlinear problem, we need to resort to pseudo-R^2, defined in terms of the residual sum of squares and total sum of squares in the original problem. Those are different numbers, and the values that result are different.&lt;/p&gt;
&lt;p&gt;If instead of the R^2 of the linearized problem, we compute the pseudo-R^2 of the original, nonlinear, fitting problem, we will get a different answer. I have argued above that in some cases, the result from the linear fit would be a better answer, mathematically, but in other cases you might be more interested in the pseudo-R^2 of the nonlinear problem. If that is the case, you can use the residualsumofsquares procedure that you have defined; it computes the residual sum of squares of the original, nonlinear, fitting problem with respect to the solution found in the linearized problem.&lt;/p&gt;
&lt;p&gt;If you want to compute the residual sum of squares of the linearized problem "by hand", you can do so as follows:&lt;/p&gt;
&lt;pre&gt;logY := log~(Y);&lt;br&gt;fitted := LinearFit([1, x], X, logY, x);&lt;br&gt;evalf(residualsumofsquares(fitted, X, logY, x); # returns 8.0527587...&lt;/pre&gt;
&lt;p&gt;So to answer your questions:&lt;br&gt;- The log transform can be used if it transforms the problem to a linear problem, which is the case for exponential and power functions (they're the same).&lt;br&gt;- If you are calculating R^2 and for that a residual sum of squares, first decide for which problem to compute them. I would think that if you can linearize the problem, then it's often best to do that first.&lt;/p&gt;
&lt;p&gt;Hope this helps,&lt;/p&gt;
&lt;p&gt;Erik Postma&lt;br&gt;Maplesoft&lt;/p&gt;
&lt;p&gt;PS: in my code I used a Maple 15 addition, the kernel function &lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=numelems"&gt;?numelems&lt;/a&gt;. I see that you are using &lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=ArrayTools/NumElems"&gt;?ArrayTools/NumElems&lt;/a&gt;, which was available before but is a little slower. A good idea if you want to be compatible with earlier Maple versions.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination#comment120059"&gt;@Andreas Madsen&lt;/a&gt; : Well, there really is no difference between an exponential function and a power function, right? The equations &lt;em&gt;y&lt;/em&gt; = &lt;em&gt;a&lt;/em&gt; * &lt;em&gt;b&lt;/em&gt;^&lt;em&gt;x&lt;/em&gt; and &lt;em&gt;y&lt;/em&gt; = &lt;em&gt;a&lt;/em&gt; * exp(&lt;em&gt;B * x)&lt;/em&gt; and &lt;em&gt;y&lt;/em&gt; = exp(&lt;em&gt;A&lt;/em&gt; + &lt;em&gt;B&lt;/em&gt; * &lt;em&gt;x&lt;/em&gt;) are all equivalent, if &lt;em&gt;A&lt;/em&gt; = exp(&lt;em&gt;a&lt;/em&gt;) and &lt;em&gt;B&lt;/em&gt; = exp(&lt;em&gt;b&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;The nice thing about doing the log transform is that that turns it into a linear fitting problem. (Both the exponential and the power fit, since they are the same.) That means that we can discuss the transformed, linear, fitting problem instead of the original nonlinear one. A perfect fit for one problem clearly translates into a perfect fit for the other; we sort of assume that a good-but-not-perfect fit for the one will still translate into a good fit for the other (and actually, the measure of fit may be better in this case than in the original, as a friend recently pointed out to me). For the linear problem, we can talk about R^2, defined in terms of the residual sum of squares and total sum of squares in the log-transformed problem; for the nonlinear problem, we need to resort to pseudo-R^2, defined in terms of the residual sum of squares and total sum of squares in the original problem. Those are different numbers, and the values that result are different.&lt;/p&gt;
&lt;p&gt;If instead of the R^2 of the linearized problem, we compute the pseudo-R^2 of the original, nonlinear, fitting problem, we will get a different answer. I have argued above that in some cases, the result from the linear fit would be a better answer, mathematically, but in other cases you might be more interested in the pseudo-R^2 of the nonlinear problem. If that is the case, you can use the residualsumofsquares procedure that you have defined; it computes the residual sum of squares of the original, nonlinear, fitting problem with respect to the solution found in the linearized problem.&lt;/p&gt;
&lt;p&gt;If you want to compute the residual sum of squares of the linearized problem "by hand", you can do so as follows:&lt;/p&gt;
&lt;pre&gt;logY := log~(Y);&lt;br&gt;fitted := LinearFit([1, x], X, logY, x);&lt;br&gt;evalf(residualsumofsquares(fitted, X, logY, x); # returns 8.0527587...&lt;/pre&gt;
&lt;p&gt;So to answer your questions:&lt;br&gt;- The log transform can be used if it transforms the problem to a linear problem, which is the case for exponential and power functions (they're the same).&lt;br&gt;- If you are calculating R^2 and for that a residual sum of squares, first decide for which problem to compute them. I would think that if you can linearize the problem, then it's often best to do that first.&lt;/p&gt;
&lt;p&gt;Hope this helps,&lt;/p&gt;
&lt;p&gt;Erik Postma&lt;br&gt;Maplesoft&lt;/p&gt;
&lt;p&gt;PS: in my code I used a Maple 15 addition, the kernel function &lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=numelems"&gt;?numelems&lt;/a&gt;. I see that you are using &lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=ArrayTools/NumElems"&gt;?ArrayTools/NumElems&lt;/a&gt;, which was available before but is a little slower. A good idea if you want to be compatible with earlier Maple versions.&lt;/p&gt;</description>
      <guid>120066</guid>
      <pubDate>Thu, 19 May 2011 23:54:26 Z</pubDate>
      <itunes:author>epostma</itunes:author>
      <author>epostma</author>
    </item>
    <item>
      <title>Thanks</title>
      <link>http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination?ref=Feed:MaplePrimes:How to calculate coefficient of determination of a nonlinear fit:Comments#comment120102</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination#comment120066"&gt;@epostma&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks Erik&lt;/p&gt;
&lt;p&gt;With your help I think I have created a procedure there allow me to calculate a R^2 or Pseudo-R^2 in almost any cases.&lt;br&gt;It looks like this:&lt;/p&gt;
&lt;p&gt;Rsquared := proc (fnType::string, inFormular, X::{array, list, rtable}, inY::{array, list, rtable}, T::symbol)&lt;br&gt;&amp;nbsp; local N, Y, formular, ssRes, ssTotal;&lt;br&gt;&amp;nbsp; N := ArrayTools:-NumElems(inY):&lt;br&gt;&amp;nbsp; Y := inY:&lt;br&gt;&amp;nbsp; formular := inFormular:&lt;br&gt;&amp;nbsp; if (fnType = "exp" or fnType = "exponential" or fnType = "power") then&lt;br&gt;&amp;nbsp; &amp;nbsp; Y := map(ln, Y):&lt;br&gt;&amp;nbsp; &amp;nbsp; formular := ln(formular):&lt;br&gt;&amp;nbsp; end if;&lt;br&gt;&amp;nbsp; ssRes := add((Y[i]-(eval(formular, T = X[i])))^2, i = 1 .. N):&lt;br&gt;&amp;nbsp; ssTotal := N*Statistics:-CentralMoment(Y, 2):&lt;br&gt;&amp;nbsp; return evalhf(1-ssRes/ssTotal);&lt;br&gt;end proc:&lt;/p&gt;
&lt;p&gt;And is used this way:&lt;br&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;X := &amp;lt;seq(i, i = 1 .. 20)&amp;gt;;&lt;br&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;Y := &amp;lt;0.07, 2, .16, .24, .36, .5, .8, 1.2, 1.8, 8, 4, 6, 9, 15, 20, 30, 43, 66.9, 100, 150&amp;gt;;&lt;br&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;fitFn := ExponentialFit(X, Y, x);&lt;br&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;R^2 = Rsquared("exp", fitFn, X, Y, x);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;Since this is my first question in mapleprimes.com I don't know how to mark this tread answered &amp;ndash; if I need to do so.&lt;/span&gt;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/120014-How-To-Calculate-Coefficient-Of-Determination#comment120066"&gt;@epostma&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks Erik&lt;/p&gt;
&lt;p&gt;With your help I think I have created a procedure there allow me to calculate a R^2 or Pseudo-R^2 in almost any cases.&lt;br&gt;It looks like this:&lt;/p&gt;
&lt;p&gt;Rsquared := proc (fnType::string, inFormular, X::{array, list, rtable}, inY::{array, list, rtable}, T::symbol)&lt;br&gt;&amp;nbsp; local N, Y, formular, ssRes, ssTotal;&lt;br&gt;&amp;nbsp; N := ArrayTools:-NumElems(inY):&lt;br&gt;&amp;nbsp; Y := inY:&lt;br&gt;&amp;nbsp; formular := inFormular:&lt;br&gt;&amp;nbsp; if (fnType = "exp" or fnType = "exponential" or fnType = "power") then&lt;br&gt;&amp;nbsp; &amp;nbsp; Y := map(ln, Y):&lt;br&gt;&amp;nbsp; &amp;nbsp; formular := ln(formular):&lt;br&gt;&amp;nbsp; end if;&lt;br&gt;&amp;nbsp; ssRes := add((Y[i]-(eval(formular, T = X[i])))^2, i = 1 .. N):&lt;br&gt;&amp;nbsp; ssTotal := N*Statistics:-CentralMoment(Y, 2):&lt;br&gt;&amp;nbsp; return evalhf(1-ssRes/ssTotal);&lt;br&gt;end proc:&lt;/p&gt;
&lt;p&gt;And is used this way:&lt;br&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;X := &amp;lt;seq(i, i = 1 .. 20)&amp;gt;;&lt;br&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;Y := &amp;lt;0.07, 2, .16, .24, .36, .5, .8, 1.2, 1.8, 8, 4, 6, 9, 15, 20, 30, 43, 66.9, 100, 150&amp;gt;;&lt;br&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;fitFn := ExponentialFit(X, Y, x);&lt;br&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;R^2 = Rsquared("exp", fitFn, X, Y, x);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;Since this is my first question in mapleprimes.com I don't know how to mark this tread answered &amp;ndash; if I need to do so.&lt;/span&gt;&lt;/p&gt;</description>
      <guid>120102</guid>
      <pubDate>Fri, 20 May 2011 14:18:32 Z</pubDate>
      <itunes:author>Andreas Madsen</itunes:author>
      <author>Andreas Madsen</author>
    </item>
  </channel>
</rss>