mle: Deriving MLE

Description Usage Arguments Examples

View source: R/mle.R

Description

Deriving MLE

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
mle(
  form,
  start,
  data,
  fixed = NULL,
  links = NULL,
  parameters = NULL,
  random = NULL,
  control = mle_control(),
  method = c("R", "TMB")
)

Arguments

form

A formula in expression form of "y ~ model"

start

A list of initial values for parameters

data

A data frame containing any variables used in the formula for the log-likelihood. (mle does not work with variables taken from the global environment; if necessary, wrap these variables in data.frame to pass them to the function.)

fixed

A list of parameter in the formula to keep fixed during optimization

links

link function for parameters (identity link as default)

parameters

A list of linear submodels and random effects

random

???

control

A list of parameter to pass to optimizer (See mle_control)

method

base R or TMB integration

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
d <- data.frame(x = 0:10, y = c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8))
fit0 <- mle(y ~ dpois(lambda = ymean), start = list(ymean = mean(d$y)), data = d)
ss <- list(ymean = mean(d$y), logsd = log(sd(d$y)))
fit3 <- mle(y ~ dnorm(mean = ymean, sd = exp(logsd)), start = ss, data = d)

set.seed(123)
x <- runif(20, 1, 10)
y <- rnorm(20, mean = 1.8 + 2.4 * x, sd = exp(0.3))
form <- y ~ dnorm(b0 + b1 * x, log_sigma)
fit <- mle(form,
  start = list(b0 = 1, b1 = 2, log_sigma = sd(y)),
  data = list(x = x, y = y), links = c(b0 = "identity", b1 = "identity", sigma = "log")
)
## linear submodels
set.seed(101)
rfp <- transform(emdbook::ReedfrogPred, nsize = as.numeric(size), random = rnorm(48))
form <- surv ~ dbinom(size = density, prob = exp(log_a) / (1 + exp(log_a) * h * density))
fit4 <- mle(form, start = list(h = 4, log_a = 2),
            parameters = list(log_a ~ poly(random)), data = rfp)

queezzz/qzmle documentation built on Nov. 24, 2021, 6:34 p.m.