Skip to contents

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).

Usage

loglik_xzd(data, model, params)

Arguments

data

list() with tags x, z and delta containing the data

model

ParamRegrModel to use for the likelihood function

params

vector with model parameters to compute likelihood function for

Value

Value of the negative log-likelihood function

Examples

# 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)
#> [1] 95.71994

# Compute negative log likelihood for wrong parameters (should be higher)
loglik_xzd(data, model, params = list(beta = c(1,2), sd = 0.5))
#> [1] 306.0526