View source: R/LikelihoodFunctions.R
loglik_xzd | R Documentation |
The log-likelihood function for a parametric regression model under random censorship with data (x,z,delta) is given by the sum of the logarithm of the conditional density of Y given X=x evaluated at z if z was uncensored or the logarithm of the conditional survival of Y given X=x evaluated at z if z was censored.
This function is one option that can be used to fit a ParamRegrModel. It
returns the negative log-likelihood value in order for optim()
to
maximize (instead of minimize).
loglik_xzd(data, model, params)
data |
|
model |
ParamRegrModel to use for the likelihood function |
params |
vector with model parameters to compute likelihood function for |
Value of the negative log-likelihood function
# Create an example dataset
n <- 100
x <- cbind(runif(n), rbinom(n, 1, 0.5))
model <- NormalGLM$new()
params.true <- list(beta = c(2,3), sd = 1)
y <- model$sample_yx(x, params = params.true)
c <- rnorm(n, mean(y) * 1.2, sd(y) * 0.5)
data <- dplyr::tibble(x = x, z = pmin(y, c), delta = as.numeric(y <= c))
# Compute negative log likelihood for true parameters
loglik_xzd(data, model, params.true)
# Compute negative log likelihood for wrong parameters (should be higher)
loglik_xzd(data, model, params = list(beta = c(1,2), sd = 0.5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.