Learn R Programming

mcmcsae (version 0.6.0)

maximize_llh: Maximize log-likelihood defined inside a sampler function

Description

Maximize log-likelihood defined inside a sampler function

Usage

maximize_llh(sampler, method = "BFGS", control = list(fnscale = -1), ...)

Arguments

sampler

sampler function.

method

optimization method, passed to optim.

control

control parameters, passed to optim.

...

other parameters passed to optim.

Value

A list of parameter values that, provided the optimization was successful, maximize the likelihood.

Examples

Run this code
# NOT RUN {
n <- 1000
dat <- data.frame(
  x = rnorm(n),
  f = factor(sample(1:50, n, replace=TRUE))
)
df <- generate_data(
  ~ reg(~x, name="beta", Q0=1) + gen(~x, factor=~f, name="v"),
  sigma.fixed=TRUE, data=dat
)
dat$y <- df$y
sampler <- create_sampler(y ~ x + gen(~x, factor=~f, name="v"), data=dat)
opt <- maximize_llh(sampler)
str(opt)
plot(df$par$v, opt$par$v); abline(0, 1, col="red")
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab