Re: G0159 : Wrong number of parameters

(Sorry! I'm unable to reply to the previous thread for some reason)

My likelihood procedure takes in a vector of initial values x0 and returns a scalar value for the log likelihood through an iterative process. The procedure compiles correctly and seems to be able to calculate the likelihood value.

x0 = {0.09, 0.062, 0.932, 0.354, 0.016, 0.058, 0.002, -0.147, 0.417};

proc log_lik(x0);
@local variables for procedure@
local t,F,beta_ll,P_ll,j_itr,beta_tl,p_tl,eta_tl,f_tl,beta_tt,F1,F2,F3,F4,
p_tt,kt,C,Q1,Q2,Q3,Q,R,sigd,sigu,sigg,rhogu,rhogd,rhodu,sig2d,sig2u,sig2g,gm1,gm0,d0,d1,siggu,siggd,sigdu,rho,
kappa,A,B1,B2,M0,M0b,M1, M1a,M1b,M2,M2a,M2b,beta,lnlik,z,rho12,sig1,sig2,sig12,h;

@Assign Parameter values @
t=cols(ymat);
d0=x0[1,1];
gm0=x0[2,1];
d1=x0[3,1];
gm1=x0[4,1];
sigu=x0[5,1];
sigg=x0[6,1];
sigd=x0[7,1];
rhodu=x0[8,1];
rhogu=x0[9,1];
siggd = 0; //by assumption
rhogd = 0;
siggd = 0;
rho = 0.969;
kappa = 0.1387;

sig2d = sigd^2;
sig2u = sigu^2;
sig2g = sigg^2;
siggu = rhogu*sigg*sigu;
sigdu = rhodu*sigd*sigu;

A = kappa/(1-rho) + (gm0-d0)/(1-rho);
B1 = 1/(1-rho*d1);
B2 = 1/(1-rho*gm1);

Beta_ll={0,0,0,0}; //@initial guess for coefficients@ (b_0_0)
P_ll = {10 10 10 10,10 10 10 10,10 10 10 10,10 10 10 10}; //@Uncertainty associated with initial guess@ (p_0_0)
eta_tl=zeros(2,t);

@Transition Equations@
F1=gm1~0~1~0;
F2=0~0~0~0;
F3=0~0~0~0;
F4=0~0~0~0;
F=F1|F2|F3|F4;
C={0 0 0, 1 0 0, 0 1 0, 0 0 1};
Q1=sig2d~siggu~siggd;
Q2=siggu~sig2g~sigdu;
Q3=siggd~sigdu~sig2u;
Q=Q1|Q2|Q3;
@Measurement Equations@
M0=gm0|(A-d1*A);
M1a=0~0;
M1b=0~d1;
M1=M1a|M1b;
M2a=1~1~0~0;
M2b=(B2*gm1-B2*d1)~0~B2~-B1;
M2=M2a|M2b;
R=0;
lnlik=0;

j_itr=2;
do until j_itr>t;
Beta_tl = F*beta_ll; //conditional expectation of beta
P_tl = F*P_ll*F' + C*Q*C'; //conditional expectation of var-beta
eta_tl[1:2,J_itr]=ymat[1:2,J_itr]-M0-M1*ymat[1:2,J_itr-1]-M2*Beta_tl; //prediction error
f_tl=M2*P_tl*M2' + R; //variance of Yt
Kt=P_tl*M2'*inv(f_tl); //kalman gain

Beta_tt = Beta_tl + Kt* eta_tl[1:2,J_itr]; //updating for beta
P_tt = (eye(1) - Kt*M2)*P_tl; //updating for var beta
sig1=(f_tl[1,1])^(0.5);
sig2=(f_tl[2,2])^(0.5);
sig12=(f_tl[1,2])^(0.5);
rho12=sig12/(sig1*sig2);
beta_ll = beta_tt; p_ll=p_tt; //set next periods values

if j_itr < start; goto skip; endif;

lnlik= lnlik-(ln(det(f_tl))+eta_tl[1:2,J_itr]'*inv(f_tl)*eta_tl[1:2,J_itr]);
//print lnlik;
skip: J_itr = J_itr+1;
endo;

retp(-lnlik);
endp;

 

{x,f,g,cov,ret} = maxlik(ymat,0,&log_lik,x0);

 

G0159 : Wrong number of parameters [maxutil.src, line 2912]
Currently active call:

File maxutil.src, line 2912, in log_lik
a0 = ll(x,z);
Traceback:

File maxutil.src, line 2912, in _max_rdd
a0 = ll(x,z);
File maxutil.src, line 423, in _max
vof = _max_rdd(lfct,0,x0,0,0,0,LLoutput,Lmaxlag,dataset,vindx,row,
File maxlik.src, line 547, in maxlik
{ x,f,g,h,retcode,Lmlfhess,Lmlitdta,Lmlcpvcp,Lmlhsvcp,_max_dat,
File maxlik.src, line 649, in <main>
endp;

2 Answers



0



The problem is as I suspected. Your likelihood procedure takes only one input, the starting values. It needs to take two inputs. Below is the description from the manual. Also, take a look at some of the Maximum Likelihood examples such as maxlik1.e, etc. They will be located in your GAUSSHOME/examples directory.

Writing the Log-likelihood Function

The user must provide a procedure for computing the log-likelihood for a matrix of observations. The procedure must have two input arguments: first, a vector of parameter values, and second, the data matrix. The output argument is the log-likelihood for the observations in the second argument evaluated at the parameter values in the first argument. Suppose that the function procedure has been named pfct, the following considerations apply:
The format of the procedure is:

logprob = pfct(x,y);

where x is a column vector of parameters of the model
and y the data matrix
The output from the procedure pfct is the vector of log-likelihoods for a set of observations.

aptech

1,773


0



Thanks a lot. I wanted to follow-up and say that I found Ronald Schoenberg's CML and Maxlik handbooks very helpful. (For those like myself that read through many past user posts to troubleshoot.)

Your Answer

2 Answers

0

The problem is as I suspected. Your likelihood procedure takes only one input, the starting values. It needs to take two inputs. Below is the description from the manual. Also, take a look at some of the Maximum Likelihood examples such as maxlik1.e, etc. They will be located in your GAUSSHOME/examples directory.

Writing the Log-likelihood Function

The user must provide a procedure for computing the log-likelihood for a matrix of observations. The procedure must have two input arguments: first, a vector of parameter values, and second, the data matrix. The output argument is the log-likelihood for the observations in the second argument evaluated at the parameter values in the first argument. Suppose that the function procedure has been named pfct, the following considerations apply:
The format of the procedure is:

logprob = pfct(x,y);

where x is a column vector of parameters of the model
and y the data matrix
The output from the procedure pfct is the vector of log-likelihoods for a set of observations.

0

Thanks a lot. I wanted to follow-up and say that I found Ronald Schoenberg's CML and Maxlik handbooks very helpful. (For those like myself that read through many past user posts to troubleshoot.)


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy