Fits a single‐covariate model (GLM or Cox) with optional standardization and a truncated‐L1 penalty on the coefficient. For GLMs it uses IRLS with a capped‐L1 update; for Cox it uses a penalized IRLS on the partial likelihood.
Arguments
- x
Numeric vector of covariate values (length n); a scalar expands to zeros.
- y
Response:
For GLMs: numeric vector of length n.
For Cox: numeric matrix with 2 columns (time, status) and n rows.
- family
A stats::family object (e.g.
gaussian(),binomial(),poisson()) or a Cox family list withfamily = "cox".- offset
Numeric scalar or vector (length n) giving the linear predictor offset (default: 0).
- standardize
Logical: if TRUE, center and scale
xbefore fitting (default: TRUE).- ties
Character: ties method for Cox partial likelihood ("efron" or "breslow", default: "efron").
- lambda
Numeric penalty weight; if
NULLor ≤ 0, defaults to \(\sqrt{2\log(n)/n}\).- tau
Numeric truncation parameter; if
NULLor ≤ 0, defaults to 0.5.
Value
A list with elements:
- intercept
Estimated intercept (after undoing standardization).
- theta
Estimated coefficient (after undoing standardization).
- loglik
Unpenalized log-likelihood at the estimated
theta.- bic
Bayesian Information Criterion: \(-2*loglik + 2\log(n)\).
Examples
if (FALSE) { # \dontrun{
set.seed(101)
n <- 50
x <- rnorm(n)
# Gaussian GLM
y_gauss <- 1.5*x + rnorm(n)
res1 <- univariate_fit(x, y_gauss, family = gaussian(), offset = 0)
# Cox example
times <- rexp(n, rate = exp(0.7*x))
status <- rbinom(n, 1, 0.6)
y_cox <- cbind(time=times, status=status)
res2 <- univariate_fit(x, y_cox, family = list(family="cox"))
} # }