index `par` by names does not work
Thanks to Marc for spotting the issue!
index par
by names does not work.
set.seed(13); x <- rnorm(1000, 5, 2)
negll <- function(par, x){ -sum(dnorm(x=x, mean=par["mean"], sd=par["sd"], log=TRUE)) }
optim(par=c(mean=1, sd=1), fn=negll, x=x, method = "L-BFGS-B", lower=c(-Inf, .0001))
The same code cannot be used in optim and optimParallel
library(optimParallel)
cl <- makeCluster(2) # set the number of processor cores
setDefaultCluster(cl=cl) # set 'cl' as default cluster
optimParallel(par=c(mean=1, sd=1), fn=negll, x=x, method = "L-BFGS-B", lower=c(-Inf, .0001))