Re: [R] Error in optim function.

2011-09-26 Thread Rolf Turner
(a) This is pretty obviously homework; the r-help list is *not* for giving help with homework. (b) *Read* the error message! (c) Your expression for the log likelihood is wrong in more than one way. (The number of observations is *not* the same thing as the number of trials for a given observa

Re: [R] Error in optim function.

2011-09-26 Thread Berend Hasselman
jango wrote: > > I'm trying to calculate the maximum likelihood estimate for a binomial > distribution. Here is my code: > > y <- c(2, 4, 2, 4, 5, 3) > n <- length(y) > binomial.ll <- function (pi, y, n) {## define log-likelihood > output <- y*log(pi)+(n-y)*(log(1-pi)) > return(outp

[R] Error in optim function.

2011-09-26 Thread jango
I'm trying to calculate the maximum likelihood estimate for a binomial distribution. Here is my code: y <- c(2, 4, 2, 4, 5, 3) n <- length(y) binomial.ll <- function (pi, y, n) {## define log-likelihood output <- y*log(pi)+(n-y)*(log(1-pi)) return(output) } binomial.mle <- optim(0.01,