C W
2015-Dec-10 15:17 UTC
[R] If I have 3 parameters, is optim() doing the same thing as Gibbs sampling?
Hi R list, I am using optim() to optimize a function with 3 parameters. #My 1-d toy example: loglikelihood of normal with x=c(2,5,3,7,-3,-2,0), find MLE of mean. p1 <- function(theta){ sum(log(dnorm(c(2,5,3,7,-3,-2,0), mean = theta, sd = 1))) +log(dnorm( theta, mean = 0.8, sd = 2)) } optimize(p1, c(-3, 5), maximum = TRUE) My question: If function p1 has 3 parameters, is it doing the same thing as Gibbs sampling? In Gibbs, we optimize parameter 1 while fixing parameter 2 and 3. Then optimize 2, fixing 1 and 3. Repeat until convergence. How does optim() choose random numbers? I am using the default, Nelder-Mead. Is optim() drawing numbers from uniform distribution? Is it picking from [-Inf, Inf]? What if I want draw from a prior N(3, 1) instead? Thanks so much! Mike [[alternative HTML version deleted]]
S Ellison
2015-Dec-10 15:28 UTC
[R] If I have 3 parameters, is optim() doing the same thing as Gibbs sampling?
> If function p1 has 3 parameters, is it doing the same thing as Gibbs sampling?No.> How does optim() choose random numbers?It doesn't, for Nelder-Mead. Nelder-Mead is a deterministic algorithm that does not need random numbers. Read up on Nelder-Mead; it - and everything else in optim() - is pretty much completely different from MCMC using a Gibbs sampling algorithm S Ellison ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}