I am trying to optimize custom likelyhood with nlminb() Arguments h and f are meant to be fixed.
example.R: compute.hyper.log.likelyhood <- function(a, h, f) { a1 <- a[1] a2 <- a[2] l <- 0.0 for (j in 1:length(f)) { l <- l + lbeta(a1 + f[j], a2 + h - f[j]) - lbeta(a1, a2) } return(l) } compute.optimal.hyper.params <- function(start, limits, h_, f_) { result <- nlminb(start, compute.hyper.log.likelyhood, h=h_, f=f_, scale = -1, lower = c(limits[1],limits[1]), upper = c(limits[2],limits[2])) return (result[[1]]) } Console launch: source('~/Desktop/Dropbox/example.R') h <- 1000 start <- c(3,3) limits <- c(0.01,100) f <- c(40,30,50) compute.optimal.hyper.params(start,limits,h,f) produces the following: Error in a2 + h : 'h' is missing Could you please explain me why? R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-pc-linux-gnu (32-bit) -- Best regards, Dmitry ______________________________________________ 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.