Hello fellow R users, Below are two cases using the "mle" operation from the stats4 package. In CASE 1 the code runs fine, in CASE 2 errors occur: CASE 1 x, alpha_current, s, and n are vectors of the same length. ll_beta<-function(b0=0,b1=0) -sum(s*b0+s*b1*x+s*alpha_current-n*log(1+exp(b0+b1*x+alpha_current))) fit_beta<-mle(ll_beta) CASE 2 The error message is as follows => Error in validObject(.Object) : invalid class "mle" object: invalid object for slot "fullcoef" in class "mle": got class "list", should be or extend class "numeric" x,s,n, and alpha are vectors of the same length (5 dimensions in this specific case). ll_alpha<-function(alpha=c(0.5,0.5,0.5,0.5,0.5)) -sum(s*b0+s*b1*x+s*alpha-n*log(1+exp(b0+b1*x+alpha))-0.5*(alpha/sigma)^2) fit_alpha<-mle(ll_alpha) MY THEORY: I think it has something to do with the fact that the function argument is a vector in CASE 2. Hope this doesn't mean I have to re-write the function in a way that it doesn't require vector inputs..... Any suggestions on how to make CASE 2 work would be appreciated. peace Narcyz. This message is intended for the addressee named and may con...{{dropped}}
Peter Dalgaard
2005-Jul-27 09:34 UTC
[R] Problem specifying "function" for "mle" operation
"Narcyz Ghinea" <Narcyz.Ghinea at swsahs.nsw.gov.au> writes:> MY THEORY: > > I think it has something to do with the fact that the function > argument is a vector in CASE 2. Hope this doesn't mean I have to > re-write the function in a way that it doesn't require vector > inputs.....You do. The innards of mle has f <- function(p) { l <- as.list(p) names(l) <- nm l[n] <- fixed do.call("minuslogl", l) } which converts the parameters to a list before calling the likelihood.> Any suggestions on how to make CASE 2 work would be appreciated.Well, either you conform or you patch mle to handle functions with vector parameters.... -- O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907