Hi Ravi,

I have generated some random variable from generalised gamma distribution,

and now I need to use them to test on my optim function. Please see below:

*##Need to install package VGAM first before calling rggamma function

library(VGAM)

x <- rggamma(500,scale=gamma(1.5)/gamma(3.5),d=0.5,k=1.5)

mlogl <- function(param){

n <- length(x)

psi <- numeric(n)

psi[1] <- 1.0

a0 <- param[1]; a1 <-param[2]; b1 <- param[3]; alpha <- param[4]; kappa <-

param[5];

for (i in 2:n) {

psi[i] <- a0 + a1*x[i-1] + b1*psi[i-1]

lam <- gamma(kappa)/gamma(kappa+(1/alpha))

ll <-

n*log(alpha/gamma(kappa))+kappa*alpha*sum(log(x))-kappa*alpha*sum(log(psi*lam))-lam^(-alpha)*sum((x/psi)^alpha)

}

return(-ll)

}

fittedparam<-optim(c(0.1,0.05,0.5,0.65,1.8),mlogl,x)*

While I do need to put some constrains on my parameters,* the parameters

param[1]~param[5] all need to be positive*. Do you know how to have this

done?

Thank you!

Carol

On Fri, May 7, 2010 at 11:12 PM, Ravi Varadhan <

[hidden email]> wrote:

> It probably means that your parameters are taking on values that are

> infeasible. You may have to impose constraints on your parameters to get a

> solution (e.g. bounds constraints). If you need better help, you have to

> send us a minimal, self-contained, reproducible example.

>

> Ravi.

>

> -----Original Message-----

> From:

[hidden email] [mailto:

[hidden email]]

> On

> Behalf Of Carol Gao

> Sent: Friday, May 07, 2010 5:53 AM

> To:

[hidden email]
> Subject: [R] problem in using optim

>

> Dear R users,

>

> When I was trying to use the function *optim* to get the MLEs, quite a few

> warning messages showed up as below:

>

> Warning in log(psi * lam) : NaNs produced

>

> I am just wondering what does this mean? Was it something wrong with my

> likelihood function or was it sth wrong with the data?

>

> Thanks in advance.

>

> Carol Gao

>

> [[alternative HTML version deleted]]

>

> ______________________________________________

>

[hidden email] mailing list

>

https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide

>

http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.

>

>

[[alternative HTML version deleted]]

______________________________________________

[hidden email] mailing list

https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide

http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.