Hi,
I'm running a likelihood analysis using the Logit.src procedure. Sometimes I encountered into this error message:
G0043 : Not implemented for complex matrices [logit.src, line 800]
then my program terminates.
Someone can help me how to handle this error so that my program could restart automatically? I see line 800 of logit.src is a cdfchic command but I am not able to handle this error by the usual trap command.
Thanks!
1 Answer
0
My line numbers are different than yours, so I am not sure exactly what the line of code is. However, looking over the code it seems pretty likely that the problem is that a negative number is being passed in the the ln function. I would recommend tracing that in the debugger to see why that is happening. It is possible that this may allow you to resolve the issue.
If this does not allow you to resolve the error such that it will come up from time to time, you can catch the error. For example, let's suppose that you have these 3 lines that are causing the problem:
//'pctall' is sometimes negative //causing 'llrest' to be complex llrest = sumc(nb.*ln(pctall)); lrx2 = -2*(llrest - llfull); //Next line errors if 'lxr2' is complex lrxp = cdfchic(lrx2,df);
You could add a line to check to see if llrest is complex, like this. Then in that case, you can return early with a scalar error code in the place of the parameter estimates, b .
llrest = sumc(nb.*ln(pctall)); //Check to see if 'llrest' is complex if iscplx(llrest); //return scalar error code with //error number of 127 in place of //parameter estimates err = error(127); retp(0,err,0,0,0,0,0,0,0,99999); endif; lrx2 = -2*(llrest - llfull); //Next line errors if 'lxr2' is complex lrxp = cdfchic(lrx2,df);
Once you have done that step, the logit procedure call will not fail with an error message, but return a scalar error code instead which you can check for. For example if your main code looked like this:
{vnam,b,vc,n,pct,mn,sd,fit,df,tol} = logit(dataset,depvar,indvar);
You could change it to:
b = error(0);
//Keep trying until 'b' is no longer a scalaer error code
do while scalmis(b);
{vnam,b,vc,n,pct,mn,sd,fit,df,tol} = logit(dataset,depvar,indvar);
endo;
Your Answer
1 Answer
My line numbers are different than yours, so I am not sure exactly what the line of code is. However, looking over the code it seems pretty likely that the problem is that a negative number is being passed in the the ln function. I would recommend tracing that in the debugger to see why that is happening. It is possible that this may allow you to resolve the issue.
If this does not allow you to resolve the error such that it will come up from time to time, you can catch the error. For example, let's suppose that you have these 3 lines that are causing the problem:
//'pctall' is sometimes negative //causing 'llrest' to be complex llrest = sumc(nb.*ln(pctall)); lrx2 = -2*(llrest - llfull); //Next line errors if 'lxr2' is complex lrxp = cdfchic(lrx2,df);
You could add a line to check to see if llrest is complex, like this. Then in that case, you can return early with a scalar error code in the place of the parameter estimates, b .
llrest = sumc(nb.*ln(pctall)); //Check to see if 'llrest' is complex if iscplx(llrest); //return scalar error code with //error number of 127 in place of //parameter estimates err = error(127); retp(0,err,0,0,0,0,0,0,0,99999); endif; lrx2 = -2*(llrest - llfull); //Next line errors if 'lxr2' is complex lrxp = cdfchic(lrx2,df);
Once you have done that step, the logit procedure call will not fail with an error message, but return a scalar error code instead which you can check for. For example if your main code looked like this:
{vnam,b,vc,n,pct,mn,sd,fit,df,tol} = logit(dataset,depvar,indvar);
You could change it to:
b = error(0);
//Keep trying until 'b' is no longer a scalaer error code
do while scalmis(b);
{vnam,b,vc,n,pct,mn,sd,fit,df,tol} = logit(dataset,depvar,indvar);
endo;