PDA

View Full Version : nonlinear regression results

mauri
05-12-2008, 06:48 AM
Hi,
I have a set of datapoints which i am trying to fit to the function
y = A*log(B+x) + C*x + D*sqrt(x)
and I am trying to use IMSL NonLinearRegression to do so.
An example of the data points i am trying to fit is attached:
The results are
A = 6.470
B = 0.827
C=-0.494
D= 4.009
I tried to compare the results with those generated by another library and those generated by other curve fitting softwares and, while the values of B, C and D agree with those calculated by IMSL NonLinearRegression, the value of A calculated with all other methods is 2.810.
Could anyone explain why am I getting different results?
Mauri

ed
05-12-2008, 11:02 AM
I tried this quickly using the JMSL NonlinearRegression (http://www.vni.com/products/imsl/jmsl/v50/manual/api/com/imsl/stat/NonlinearRegression.html) class and get the 2.81 value for A.

Can you tell us which version and IMSL product you're using? If you follow the example below and still get a different result, we'd be happy to look into it but would probably need your example code.

The code and results are included below; the code is based off of Example 1 in the documentation.

OUTPUT:
The computed regression coefficients are:
2.8102886812924983
0.8274741334082188
-0.4943239962786323
4.009283745461694
The sums of squares for error is 0.12211509207486902

import com.imsl.stat.*;

public class ForumNLR {
public static void main(String args[])
throws NonlinearRegression.TooManyIteration***ception,
NonlinearRegression.NegativeFreqException,
NonlinearRegression.NegativeWeightException {
NonlinearRegression.Function f = new NonlinearRegression.Function() {

public boolean f(double theta[], int iobs, double frq[], double wt[], double e[]) {
double xdata[] = {0.048,0.091,0.091,0.091,0.082,0.13,0.138,0.176,0. 214,0.226,
0.269,0.294,0.327,0.371,0.417,0.454,0.493,0.558,0. 606,0.656,0.701,0.765,
0.814,0.879,0.93,0.991,1.073,1.13,1.194,1.279};
double ydata[] = {0.6,0.8,0.8,0.8,1,1.2,1.4,1.6,1.8,2,2.2,2.4,2.6,2 .8,3,3.2,
3.4,3.6,3.8,4,4.2,4.4,4.6,4.8,5,5.2,5.4,5.6,5.8,6} ;
boolean iend;
int nobs = 30;

if(iobs < nobs){
wt = 1.0;
frq = 1.0;
iend = true;
e = ydata[iobs]
- theta * Math.log(theta + xdata[iobs])
- theta * xdata[iobs]
- theta * Math.sqrt(xdata[iobs]);
} else {
iend = false;
}
return iend;
}
};

int nparm = 4;
double theta[] = {1, 1, 1, 1};
NonlinearRegression regression = new NonlinearRegression(nparm);
regression.setGuess(theta);
double coef[] = regression.solve(f);
System.out.println("The computed regression coefficients are:");
for (int i=0; i<coef.length; i++) {
System.out.println("\t" + coef[i]);
}
double sse = regression.getSSE();
System.out.println("The sums of squares for error is " + sse);
}
}

ed
05-12-2008, 11:10 AM
On a whim, I just re-ran this in Java and changed the "Math.log" method call to "Math.log10" and got the following results:

The computed regression coefficients are:
6.470818030994914
0.8274702917257918
-0.49431002457446555
4.009304579667014
The sums of squares for error is 0.12211509207523491

So I guess you need to make sure you're calling the same LOG function in every program. It's interesting that the other parameters do not change at all.

mauri
05-12-2008, 12:39 PM
:o now that explains it! thanks for your help, Ed! Much appreciated

mecej4
04-25-2015, 08:37 AM
It's interesting that the other parameters do not change at all.Switching from natural to common logarithms is equivalent to scaling A by ln 10. The remaining fit coefficients (B, C and D) are not affected by this scaling, so there is no surprise here.