[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multiple non-linear regression analysis



"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