N/A
Posts: 0

# PROC NLMIXED and coding a Likelihook function

Hey is anyone has an idea about how to code or spot the mistake in the statement below in coding a mixed negative binomial distribution .The code has two data col1 and new_data_1 and in the proc nlmixed a likelihood function is created with those different parameters and it supposed to return me the maximum
***************CODE***************************************
proc NLMIXED data=call.Merging;
parms gam0=.1,gam1=0.1,gam2=0.1,gam3=0.1,
gam4=.1,sig0=.1,sig1=.1,sig2=.1,sig3=.1,
sig4=.1,ome0=.1,ome1=.1,ome2=.1,ome3=.1,
ome4=.1,bet0=.1,bet1=.1,bet2=.1,bet3=.1,bet4=.1
phi=.1,p=.1;tho=.1;
array gamma{5};
array oldg{5};
array sigma{5};
array omega{5};
array beta{5};
gamma{1} = gam0; sigma{1} = sig0; omega{1} = ome0; beta{1} = bet0;
gamma{2} = gam1; sigma{2} = sig1; omega{2} = ome1; beta{2} = bet1;
gamma{3} = gam2; sigma{3} = sig2; omega{3} = ome2; beta{3} = bet2;
gamma{4} = gam3; sigma{4} = sig3; omega{4} = ome3; beta{4} = bet3;
gamma{5} = gam4; sigma{5} = sig4; omega{5} = ome4; beta{5} = bet4;
oldg{1}=gamma{1};
do i=2 to 5;
*gamma{i}+gamma{i-1};
temp = gamma{i};
gamma{i} = temp + gamma{i-1};
oldg{i}=gamma{i}-gamma{i-1};
end;
thoat=(1-tho)**new_data_1;
j=1;
fS=0;
sS=0;
do j=1 to 5;
*temp=gamma{i};
fS+(thoat)*((p*gamma{j}+1-p)**new_data_1);
k=j;
do k =j to 5;
/*ol=oldg{k};sig=sigma{k};omeg=omega{k};bet=beta{k};*/
sS+oldg{k}*(1/sigma{k})*phi*((log(omega{k})-log(col1))/sigma{k});
end;
II=fS*p*sS*beta{j};
logII=log(II);
end;
model new_data_1~General(logII);
run;
********************************log message error***************************
The log message is a note :

NOTE: Execution error for observation 1.
NOTE: PROCEDURE NLMIXED used (Total process time):
real time 1.19 seconds
cpu time 0.18 seconds
Regular Contributor
Posts: 171

## Re: PROC NLMIXED and coding a Likelihook function

I'm not going to try to look at all of your code. However, I would note that it is much easier to debug problems like "Execution error for observation 1" if you write a data step version of your code. In the data step version, you have to change the PARMS statement to a RETAIN statement and eliminate the equal sign between the parameter and the initial value. You also have to get rid of the commas between parameter assignments.

(Parenthetical note 1: your PARMS statement could be written just as easily as

parms gam0-gam4 sig0-sig4 ome0-ome4 bet0-bet4 phi p 0.1;

If you had written your PARMS statement that way, all you would need to do is change the keyword PARMS to RETAIN for that part of the code to work in a data step.)

(Parenthetical note 2: the string THO is not actually named on your PARMS statement and will be treated as a variable in your NLMIXED code rather than as a parameter. Is that what you want? It would appear that you wanted that on the PARMS statement, but placed a semicolon before the assignment of THO=.1

In addition to changing the PARMS statement to a RETAIN statement, you have to eliminate (or comment out) the MODEL statement. The data step would not know what to do with that line of code.

After you have made appropriate modifications of your code so that it can be executed in a data step, you will get more informative errors regarding the cause of the execution error reported by the NLMIXED procedure.
N/A
Posts: 0

## Re: PROC NLMIXED and coding a Likelihook function

thanks for the reply but can you be more specific with the data step version of the code ??
Regular Contributor
Posts: 171

## Re: PROC NLMIXED and coding a Likelihook function

You mean, can I write the data step for you? I could do that - but I really don't want to have to do that. I have told you exactly what modifications you need to make to your code in order to convert it from NLMIXED to data step code. Everything in your code is data step code except the invocation statement (how would you change PROC NLMIXED data=call.Merging; into data step code?) , the PARMS statement (which I covered in considerable detail previously), and the MODEL statement (which I discussed previously). Modify or remove each of these as necessary for the code to be a legitimate data step.
N/A
Posts: 0

## Re: PROC NLMIXED and coding a Likelihook function

I understand now what you meant by data step version of it .when i put the code into a data step mode it appears that the log has negative arguments which makes the data step failing to execute all the iterations.This is one problem and the other i cant make sense of it is the note
NOTE: DELETE statement executed.
I googled it but i dont see any such log message on the web .
Anyone has an idea??thanks
Contributor
Posts: 40