Calculates the log-likelihood of a single covariate effect under either a generalized linear model (GLM) family or a Cox proportional hazards model.
Arguments
- x
Numeric vector of length n: covariate values.
- y
For GLMs: numeric vector of length n; for Cox: numeric matrix with two columns (time, status) and n rows.
- family
A GLM family object (e.g.
gaussian(),binomial(),poisson()) or a Cox family list with elementfamily="cox".- theta
Numeric scalar: coefficient at which to evaluate the log-likelihood.
- offset
Numeric scalar or vector of length n: offset in the linear predictor.
- intercept
Numeric scalar: intercept term in the linear predictor (for GLM only). Default is 0.
- ties
Character string: tie-handling method for Cox partial likelihood; one of
"efron"or"breslow".
Examples
if (FALSE) { # \dontrun{
# Gaussian example
x <- rnorm(100)
y <- 1.5 + 2 * x + rnorm(100)
univariate_loglik(x, y, family = gaussian(), theta = 2, intercept = 1.5)
# Binomial example
x <- rnorm(200)
eta <- -1 + 1.5 * x
p <- plogis(eta)
y <- rbinom(200, 1, p)
univariate_loglik(x, y, family = binomial(link = "logit"),
theta = 1.5, intercept = -1)
# Cox example (note: intercept not used in Cox models)
x <- rnorm(50)
times <- rexp(50)
status <- rbinom(50, 1, 0.5)
ymat <- cbind(times, status)
univariate_loglik(x, ymat, family = list(family = "cox"),
theta = 0.5, offset = 0, ties = "efron")
} # }