Skip to content

How to set parameters constraints in a function? (Matt Shotwell)

1 message · Matt Shotwell

#
When there is a constraint like this, it is often the case that the
likelihood function may the value zero. Hence, the log-likelihood may
take the value -Inf. You could impose this constraint with something
like 

if( kappa >= alpha ) {
    ll <- -Inf
} else 
    ll <- n*log(alpha/gamma(kappa))+
          kappa*alpha*sum(log(x))-
          n*kappa*alpha*log(lam)-
          kappa*alpha*sum(log(psi))-
          lam^(-alpha)*sum((x/psi)^alpha)
}

However, if you are using the 'optim' function, or some other function
for optimization, you may prefer to impose this constraint by telling
the optimization routine not to search at values in ( kappa >= alpha ).

Also, you may find it helpful to pass the variable 'x' as part of the
function call (i.e. mll <- function(param, x). This may avoid some
hard-to-diagnose errors.

-Matt
On Mon, 2010-05-24 at 22:31 +1000, Carol Gao wrote: