Page 1 of 1

Basic NLS Help Needed

Posted: Tue Jul 05, 2011 3:06 pm
by jennie
Hi,

I am new to eviews and I am trying to run a nonlinear least squares estimation.
I am having trouble programming it and some advice/help would be really great.

The data came from a survey.
I have 28 questions for each participant and i number of of participants.
Each participant is represented by a separate series right now in the workfile.

My equation is:

( p1^c(1) / (p1^(c(1)) - (1-p1)^c(1)) ^ (1/c(1)) ) * z1 ^ c(2) + (1 - ( p1^c(1) / (p1^(c(1)) - (1-p1)^c(1)) ^ (1/c(1)) ) * z2 ^c(2) = series{!i} ^ c(2)

Where p1, z1, z2 are each a series with 28 rows.
series{!i} is a series for each participant from i = 1 to 100 and each particpant and has 28 rows.

I need to estimate c(1) and c(2) in this equation.

When I try to do this I get an error that ^ function given out of range argument.

Code: Select all

' Create a group of the series of subjects group tempGroup for !i = 1 to 100 if !i <10 then tempGroup.add series0{!i} else tempGroup.add series{!i} endif next 'use a starting value of 1 for coefficient 1 and coeffecient 2 'note: I have attempted this with and without a starting value param c(1) 1 c(2) 1 system sys1 for !i = 1 to 100 sys1.append (nn_p1^c(1)) / (nn_p1^c(1) + (1- nn_p1)^c(1)) ^ (1/c(1)) * nn_z1^c(2)+ (1- (nn_p1^c(1)) / (nn_p1^c(1) + (1- nn_p1)^c(1)) ^ (1/c(1))) * nn_z2^c(2) = tempGroup(!i)^c(2) next sys1.ls
Any help/advice would be greatly appreciated. I am feeling pretty lost right now,

Thanks,
Jen

Re: Basic NLS Help Needed

Posted: Tue Jul 05, 2011 3:20 pm
by EViews Gareth
Could you provide the data?

Re: Basic NLS Help Needed

Posted: Tue Jul 05, 2011 8:19 pm
by jennie
Hi,

Here is a copy of the workfile I am using,

Thanks,

Jen

Re: Basic NLS Help Needed

Posted: Wed Jul 06, 2011 7:37 am
by jennie
So I think that in this case I do not want to use a system for the equations, as I need to estimate c(1) and c(2) per subject.

I am trying to loop through the subjects one at a time.
Code looks like this now....

Code: Select all

'Create a group for the subjects. 'Will loop through these for equations after group tempGroup for !i = 1 to 96 if !i <10 then tempGroup.add series0{!i} else tempGroup.add series{!i} endif next 'Start value for coefficient 1 and 2 is 1 'Eventually may need to constrain c(1) between 0.01 and 2 'Eventually may need to constrain c(2) between 0.001 and 10 param c(1) 1 c(2) 1 'loop through each subject and estimate nls for !j = 1 to 96 equation eq{!j}.ls (nn_p1^c(1)) / ( nn_p1^c(1) + (1 - nn_p1)^c(1) ) ^ (1/c(1)) * ( nn_z1 ^ c(2) ) + ( 1 - (nn_p1^c(1)) / ( nn_p1^c(1) + (1 - nn_p1)^c(1) ) ^ (1/c(1)) ) * ( nn_z2 ^ c(2)) = tempGroup(!j)^c(2) next
Error I am getting is Log of non positive in analytic derivatives....any ideas?

Re: Basic NLS Help Needed

Posted: Wed Jul 06, 2011 12:25 pm
by EViews Glenn
It's a tricky model to estimate since you've got exponents of exponents which can blow up or cause range errors. After playing around with it, I don't think it's an EViews problem, I think it's a model problem (incidentally, using numeric derivatives gets you farther, but you still end up with out-of-range errors).

Re: Basic NLS Help Needed

Posted: Wed Jul 06, 2011 12:44 pm
by jennie
Thanks for checking....I will keep playing with it and see if I can get something out...

Jen