MaxLikMT problem

When I run the following code:

library maxlikmt;
z0 = { 8.3 1, 10.3 2, 19.0 3, 16.0 4, 15.6 5, 19.8 7 };
proc lnlk(struct PV p, struct DS d);
local dev,s2,b,z;
b = pvUnpack(p,"b");
z = d.dataMatrix;
dev = z[.,1] - b[1]*(1 - exp(-b[2]*z[.,2]));
s2 = dev'dev/rows(dev);
retp(lnpdfmvn(dev,s2));
endp;
struct DS d0;
d0 = dsCreate();
d0.datamatrix = z0;
start = { 20, .24 };
struct PV p0;
p0 = pvPack(pvCreate,start);
struct maxlikmtControl c0;
struct maxlikmtResults out;
out = maxlikmt(&lnlk,p0,d0,c0);
call maxlikmtprt(out);

I get the following error message:

 

G0159 : Wrong number of parameters [pv.src, line 2585]
Currently active call:

File pv.src, line 2585, in pvPack
retp(p1);
Traceback:

File pv.src, line 2585, in <main>
retp(p1);

 

I use

GAUSS 19 for Windows 64 19.1.2, 4494

and:

Maximum Likelihood MT 3.0 3.0.1

Thank you in advance

1 Answer



0



The problem is that pvPack procedure requires a third input which is the name of these parameters. I will post a corrected full version at the bottom of this response.

However, I would not use the DS structure of the PV structure. You can make the code quite a bit shorter like this:

library maxlikmt;

z0 = { 8.3 1, 
       10.3 2, 
       19.0 3, 
       16.0 4, 
       15.6 5, 
       19.8 7 };

// Loglikelihood procedure
// Notice the final input 'ind'
// 'ind' tells you whether maxlikmt
// would like you to compute the gradient, or Hessian
// This is optional. You can ignore it as we do here.
proc lnlk(b, z, ind);
    local dev,s2;

    dev = z[.,1] - b[1]*(1 - exp(-b[2]*z[.,2]));
    s2 = dev'dev/rows(dev);

    // maxlikmt returns a result structure
    // so you can return the function value
    // and optionally the gradient and Hessian.
    struct modelResults out;
    out.function = lnpdfmvn(dev,s2);

    retp(out);
endp;

// Create starting parameters
start = { 20, .24 };

// Declare results struct to hold
// output from estimation
struct maxlikmtResults out;

// Perform estimation and print output
out = maxlikmt(&lnlk,start,z0);
call maxlikmtprt(out);

In this version above, we opted not to use the PV or DS structure and pass the data matrices in directly. Also, since we did not modify any default settings, we did not pass in the maxlikmtControl structure.

You can choose to use the PV structure or pass in the starting parameter values independently of whether you use the DS and control structure. It does not have to be all-or-none.

As promised here is the corrected longer version which will also work, but is much longer.

library maxlikmt;

z0 = { 8.3 1, 
       10.3 2, 
       19.0 3, 
       16.0 4, 
       15.6 5, 
       19.8 7 };

// Loglikelihood procedure
// Notice the final input 'ind'
// 'ind' tells you whether maxlikmt
// would like you to compute the gradient, or Hessian
// This is optional. You can ignore it as we do here.
proc lnlk(struct PV p, struct DS d, ind);
    local dev,s2,b,z;

    b = pvUnpack(p,"b");
    z = d.dataMatrix;

    dev = z[.,1] - b[1]*(1 - exp(-b[2]*z[.,2]));
    s2 = dev'dev/rows(dev);

    // maxlikmt returns a result structure
    // so you can return the function value
    // and optionally the gradient and Hessian.
    struct modelResults out;
    out.function = lnpdfmvn(dev,s2);

    retp(out);
endp;

// Declare DS struct
// and fill with extra data
struct DS d0;
d0 = dsCreate();
d0.datamatrix = z0;

// Create starting parameters
// and add to PV struct with name 'b'
start = { 20, .24 };
struct PV p0;
p0 = pvPack(pvCreate(),start, "b");

// Declare maxlikmtControl struct
// and fill with default settings
struct maxlikmtControl c0;
c0 = maxlikmtControlCreate();

// Declare results struct to hold output
// from estimation
struct maxlikmtResults out;

// Perform estimation and print output
out = maxlikmt(&lnlk,p0,d0,c0);
call maxlikmtprt(out);

aptech

1,773

Your Answer

1 Answer

0

The problem is that pvPack procedure requires a third input which is the name of these parameters. I will post a corrected full version at the bottom of this response.

However, I would not use the DS structure of the PV structure. You can make the code quite a bit shorter like this:

library maxlikmt;

z0 = { 8.3 1, 
       10.3 2, 
       19.0 3, 
       16.0 4, 
       15.6 5, 
       19.8 7 };

// Loglikelihood procedure
// Notice the final input 'ind'
// 'ind' tells you whether maxlikmt
// would like you to compute the gradient, or Hessian
// This is optional. You can ignore it as we do here.
proc lnlk(b, z, ind);
    local dev,s2;

    dev = z[.,1] - b[1]*(1 - exp(-b[2]*z[.,2]));
    s2 = dev'dev/rows(dev);

    // maxlikmt returns a result structure
    // so you can return the function value
    // and optionally the gradient and Hessian.
    struct modelResults out;
    out.function = lnpdfmvn(dev,s2);

    retp(out);
endp;

// Create starting parameters
start = { 20, .24 };

// Declare results struct to hold
// output from estimation
struct maxlikmtResults out;

// Perform estimation and print output
out = maxlikmt(&lnlk,start,z0);
call maxlikmtprt(out);

In this version above, we opted not to use the PV or DS structure and pass the data matrices in directly. Also, since we did not modify any default settings, we did not pass in the maxlikmtControl structure.

You can choose to use the PV structure or pass in the starting parameter values independently of whether you use the DS and control structure. It does not have to be all-or-none.

As promised here is the corrected longer version which will also work, but is much longer.

library maxlikmt;

z0 = { 8.3 1, 
       10.3 2, 
       19.0 3, 
       16.0 4, 
       15.6 5, 
       19.8 7 };

// Loglikelihood procedure
// Notice the final input 'ind'
// 'ind' tells you whether maxlikmt
// would like you to compute the gradient, or Hessian
// This is optional. You can ignore it as we do here.
proc lnlk(struct PV p, struct DS d, ind);
    local dev,s2,b,z;

    b = pvUnpack(p,"b");
    z = d.dataMatrix;

    dev = z[.,1] - b[1]*(1 - exp(-b[2]*z[.,2]));
    s2 = dev'dev/rows(dev);

    // maxlikmt returns a result structure
    // so you can return the function value
    // and optionally the gradient and Hessian.
    struct modelResults out;
    out.function = lnpdfmvn(dev,s2);

    retp(out);
endp;

// Declare DS struct
// and fill with extra data
struct DS d0;
d0 = dsCreate();
d0.datamatrix = z0;

// Create starting parameters
// and add to PV struct with name 'b'
start = { 20, .24 };
struct PV p0;
p0 = pvPack(pvCreate(),start, "b");

// Declare maxlikmtControl struct
// and fill with default settings
struct maxlikmtControl c0;
c0 = maxlikmtControlCreate();

// Declare results struct to hold output
// from estimation
struct maxlikmtResults out;

// Perform estimation and print output
out = maxlikmt(&lnlk,p0,d0,c0);
call maxlikmtprt(out);


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.