Dear list-members,

I discover recently bbmle package from an answer in r-list. It makes some analyses more easily to solve. However I have one problem using fixed parameter of mle2 and one question about parametrization of mle2. I send the question directly to the maintainer of the package but I get no answer still.
If anyone has solution, it would be great. Thanks.
Sincerely,

Marc Girondot

I make a very simplified version of the problem I have:
First, a version that works perfectly. It fits simply a Gaussian distribution from a set of data:
# generate data from Gaussian distribution
set.seed(1001)
df <- data.frame(A=rnorm(50, 10, 2))

# the function that return log L
knorm <- function(x, mean, sd, log=FALSE) {
  l <- dnorm(x, mean, sd, log=TRUE)
    if (log) l else exp(l)
}

# fit data using mle2. All is ok
r <- mle2(A ~ knorm(mean=m, sd=s), data=df, start=list(m=10, s=2), control=list(maxit=5000))

Then I try to fix one parameter, here sd; and I have problem:
# does not work
r <- mle2(A ~ knorm(mean=m), fixed=list(sd=2), data=df, start=list(m=10), control=list(maxit=5000))

Probably I make an error but I cant find what is wrong.

Second, I try to implement parameters as a vector within the list. I don't know if it is possible. But at least with this try, it does not work:
knorm <- function(x, par, log=FALSE) {
  l <- dnorm(x, par["mean"], par["sd"], log=TRUE)
    if (log) l else exp(l)
}

# does not work
r <- mle2(A ~ knorm(par=p), data=df, start=list(p=structure(c(10, 12), .Names = c("mean", "sd"))), control=list(maxit=5000))

Is it not possible or I make a mistake ?

______________________________________________
R-help@r-project.org 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.

Reply via email to