objfun function

Objective function

Objective function

Get the contributions of an objective function. For glm

these are the (weighted) log-likelihood contributions, for lm the negative (weighted) squared error.

objfun(x, ...) ## S3 method for class 'survreg' objfun(x, newdata = NULL, weights = NULL, ...) ## S3 method for class 'lm' objfun(x, newdata = NULL, weights = NULL, ...) ## S3 method for class 'glm' objfun(x, newdata = NULL, weights = NULL, log = TRUE, ...)

Arguments

  • x: model object.
  • ...: further arguments passed on to objfun methods.
  • newdata: optional. New data frame. Can be useful for model evaluation / benchmarking.
  • weights: optional. Prior weights. See glm or lm.
  • log: should the log-Likelihood contributions or the Likelhood contributions be returned?

Returns

vector of objective function contributions.

Examples

## Example taken from ?stats::glm ## Dobson (1990) Page 93: Randomized Controlled Trial : counts <- c(18,17,15,20,10,20,25,13,12) outcome <- gl(3,1,9) treatment <- gl(3,3) print(d.AD <- data.frame(treatment, outcome, counts)) glm.D93 <- glm(counts ~ outcome + treatment, family = poisson()) logLik_contributions <- objfun(glm.D93) sum(logLik_contributions) logLik(glm.D93) if(require("survival")) { x <- survreg(Surv(futime, fustat) ~ rx, ovarian, dist = "weibull") newdata <- ovarian[3:5, ] sum(objfun(x)) x$loglik objfun(x, newdata = newdata) }
  • Maintainer: Heidi Seibold
  • License: GPL-2 | GPL-3
  • Last published: 2024-11-08

Useful links