[R] In optim() function, second parameter in par() missing

colstat colstat at gmail.com
Mon Sep 5 16:30:24 CEST 2011


Hi,
First time using the optim(), can someone please tell me what I am doing
wrong?  The error looks like this

Error in .Internal(pnorm(q, mean, sd, lower.tail, log.p)) : 
  'sd' is missing


An example of the error
dat = c(20, 19, 9, 8, 7, 4, 3, 2)
dat_mu=mean(dat)
dat_s=sd(dat)

max.func = function(dat, mu, sd) {
    pnorm(dat, mu, sd)
}

optim(fn=max.func, dat=dat, par=c(mu=dat_mu, s=dat_s))

I get sd is missing error.  If I wrote par=c(s=dat_s, mu=dat_mu) , then it
tells me mu is missing.  Can someone please help?

Thanks!

Colin


--
View this message in context: http://r.789695.n4.nabble.com/In-optim-function-second-parameter-in-par-missing-tp3791391p3791391.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list