Your proposed solution creates a scalar, not a vector of indicators.
Try something like this instead (using the dot-conditional operator):
maxlik(const vP, const adFunc, const avScore, const amHessian)
{
decl m=vP[0], s=vP[1], vind = s_mZ .> -m / s .? -1 .: 1;
adFunc[0]=meanc((s_mZ * s + m) .^ vind);
}
Assuming that z is defined outside (which is why I called it s_mZ).
Perhaps this can be simplified to:
maxlik(const vP, const adFunc, const avScore, const amHessian)
{
decl m=vP[0], s=vP[1], x = s_mZ * s + m;
adFunc[0]=meanc(x .^ (x .> 0 .? -1 .: 1));
}
Jurgen
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
oxoxoxox US OxMetrics user conference 2010
oxoxoxox George Washington University, Washington DC
oxoxoxox 18-19 March 2010
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
Dr Jurgen A Doornik
University of Oxford, Nuffield College, Oxford OX1 1NF
tel. UK: +44-1865-278610 fax +44-1865-278621
http://www.doornik.com
http://www.oxmetrics.net
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
Shuai Yang wrote:
> Hi all,
>
> I am wondering how to code a log likelihood function with a indicator in the
> formula? The log likelihood function is as follow:
>
> L(m,s)=Ķē(Zt*s+m)^I
>
> I=1, if Zt > -m/s;
> I=-1, otherwise;
>
> I am wondering if I can add this indicator I when define the log likelihood in
> the following way:
>
>
> maxlik(const vP, const adFunc, const avScore, const amHessian)
> {
> decl m=vP[0][], s=vP[1][];
>
> if(z>-m/s)
> I=1;
> else
> I=-1;
> adFunc[0]=sumc((z.*s+m).^I);
> }
>
> Many thanks,
>
> Shuai
|