plot_ll: Plot Log-Likelihood vs. Values of One Parameter

Description Usage Arguments Details Value Examples

View source: R/plot_ll.R

Description

Generates plot of log-likelihood vs. one parameter of interest while other parameters are held fixed at certain values (e.g. MLEs). This is not a profile likelihood, and is mainly intended for use with a Shiny app.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
plot_ll(
  start,
  objective,
  lower = -Inf,
  upper = Inf,
  xaxis_param = 1,
  xaxis_range = NULL,
  param_values = NULL,
  mles = NULL,
  return_info = FALSE
)

Arguments

start

See nlminb.

objective

See nlminb.

lower

See nlminb.

upper

See nlminb.

xaxis_param

Integer value specifying which parameter should be plotted on the x-axis.

xaxis_range

Numeric vector specifying x-axis range over which to vary the parameter of interest. Only values with likelihood ratio > 0.01 are ultimately plotted.

param_values

Numeric vector of values to use for other parameters in model, in case you want an additional curve for log-likelihood function vs. parameter of interest at certain non-MLE values for other parameters. For example, if there are 3 parameters and xaxis_param = 2, you could set param_values = c(0, NA, 0).

mles

Numeric vector of previously obtained maximum likelihood estimates.

return_info

Logical value for whether to return the estimated MLEs and 99.99% confidence intervals for parameters rather than create the plot.

Details

Note that objective should be the negative log-likelihood function, since internal optimization uses (nlminb), which does minimization.

Value

Plot of log-likelihood vs. value of parameter of interest, generated by ggplot.

Examples

1
2
3
4
5
6
7
# Generate normal data, define log-likelihood function, and plot likelihood
set.seed(123)
x <- rnorm(100, mean = 0.5, sd = sqrt(0.25))
ll.f <- function(theta) {
  return(-sum(dnorm(x, log = TRUE, mean = theta[1], sd = sqrt(theta[2]))))
}
plot_ll(start = c(0, 1), objective = ll.f, lower = c(-Inf, 1e-6))

vandomed/dvmisc documentation built on Oct. 2, 2020, 9:50 p.m.