objfun {model4you} | R Documentation |
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, ...)
x |
model object. |
... |
further arguments passed on to |
newdata |
optional. New data frame. Can be useful for model evaluation / benchmarking. |
weights |
|
log |
should the log-Likelihood contributions or the Likelhood contributions be returned? |
vector of objective function contributions.
## 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) }