Re: multiple non-linear regression analysis [message #24684] |
Tue, 17 April 2001 14:29  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
"Kenlo Nishida" <kenlo@ntsg.umt.edu> writes:
>
> How can I make multiple non-linear regression analysis with IDL?
> I know "LMFIT" command can make a non-linear regression analysis
> for a single independent variable. However, I want to know
> an appropriate command or function of IDL which provide me with
> a fitting of an arbitrary non-linear function with two or more
> independent variables. I mean, I want to determine the following
> three parameters (a, b, c):
>
> y=f(x1, x2, x3; a, b, c)
>
> Here x1, x2, and x3 are arrays of independent variables each
> containing n data. y is an array of dependent variable with
> n data. a, b, and c are scalars (parameters) which determine
> the non-linear function f(x1, x2, x3).
Similar questions and answers:
http://cow.physics.wisc.edu/~craigm/idl/fitqa.html#multivar
http://cow.physics.wisc.edu/~craigm/idl/archive/msg04249.htm l
By the way, you should not use LMFIT for two reasons. The first
reason is that LMFIT cannot handle more than one independent variable.
The second is that LMFIT is very inefficient since it calls your
function once for each data point, instead of as a vector.
Use CURVEFIT (IDL built-in) or MPFITFUN+MPFIT from my web page. The
MPFIT2DFUN function is a specialization for fitting images.
The technique I refer to in these two articles is easy to implement.
Since neither CURVEFIT nor MPFIT require any special structure for
your independent variable, "X", you can in principle make it have any
structure you'd like.� In this case it would be a N_obs x 3 array, one
row for each independent variable. Then in your fitting function you
would break the array into its components again.
Good luck,
Craig
Web page: http://cow.physics.wisc.edu/~craigm/idl/idl.html
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: multiple non-linear regression analysis [message #24685 is a reply to message #24684] |
Tue, 17 April 2001 14:39   |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
"Kenlo Nishida" <kenlo@ntsg.umt.edu> writes:
> Dear IDL news group:
> How can I make multiple non-linear regression analysis with IDL?
> I know "LMFIT" command can make a non-linear regression analysis
> for a single independent variable. However, I want to know
> an appropriate command or function of IDL which provide me with
> a fitting of an arbitrary non-linear function with two or more
> independent variables. I mean, I want to determine the following
> three parameters (a, b, c):
> y=f(x1, x2, x3; a, b, c)
> Here x1, x2, and x3 are arrays of independent variables each
> containing n data. y is an array of dependent variable with
> n data. a, b, and c are scalars (parameters) which determine
> the non-linear function f(x1, x2, x3).
The simplest way to do this is to define your function so that the input array
is a structure. For example, suppose that x1, x2, x3 are all floating point
arrays of size N. You could then define your structure via
s = {x1: 0.0, x2: 0.0, x3: 0.0}
s = replicate(s, n_elements(x1))
s.x1 = x1
s.x2 = x2
s.x3 = x3
Thus, s is a structure array of N elements, and an individual element s(i)
contains x1(i), x2(i), and x3(i). For example
IDL> help,s
S STRUCT = -> <Anonymous> Array[100]
IDL> help,s(0),/str
** Structure <403eeb48>, 3 tags, length=12, refs=2:
X1 FLOAT -0.923884
X2 FLOAT 0.192019
X3 FLOAT -0.277066
You could then write your function along the lines of
function myfunc, s, a
return, a[0] + a[1]*s.x1 + a[2]*s.x2 + a[3]*s.x3
end
You can then put this function into a fitting routine in the normal manner.
(With appropriate changes for whatever peculiarities a particular fitting
routine may require. For example, LMFIT wants the partial derivatives returned
as extra dimensions in the result.)
Bill Thompson
|
|
|
Re: multiple non-linear regression analysis [message #24795 is a reply to message #24685] |
Thu, 19 April 2001 23:38  |
Kenlo Nishida
Messages: 5 Registered: April 2001
|
Junior Member |
|
|
Thank you Bill Thompson for advice about multiple nonlinear regression.
I tried to use LMFIT by setting independent variable in structure as
you told, but the IDL refused to process LMFIT function with structure.
Error message is "% FLOAT: Struct expression not allowed in this context:
X."
The following is my test program:
------------------- start of test.pro ----------
function fn, s, a
a=float(a)
f=a[0]*s.x1+a[1]*s.x2
return, [f, s.x1, s.x2]
end
pro test
s={x1: 0.0, x2: 0.0}
x1=findgen(10)
x2=x1*x1
s=replicate(s, 10)
s.x1=x1
s.x2=x2
y=1.2*x1+2.3*x2
a=[0.1, 0.1]
fit=lmfit(s,y,a,function_name='fn')
end
------------------- end of test.pro ---------------------
Then the performance and error message is like this:
IDL> .compile test
% Compiled module: FN.
% Procedure was compiled while active: TEST. Returning.
% Compiled module: TEST.
IDL> test
% FLOAT: Struct expression not allowed in this context: X.
% Error occurred at: LMFIT 245
/usr/local/rsi/envi_3.1/idl_5.1/lib/lmfit.pro
% TEST 17 test.pro
% $MAIN$
% Execution halted at: TEST 17 test.pro
IDL>
Kenlo Nishida
kenlo@ntsg.umt.edu
|
|
|