R/deviance.sgdnet.R

#' Deviance for sgdnet Object
#'
#' Return the deviance for an object of class `"sgdnet"`, typically
#' from a fit with [sgdnet()]. `deviance.cv_sgdnet()` is a simple wrapper
#' that calls [deviance.sgdnet()] on the fit to full data from [cv_sgdnet()].
#'
#' This functions returns the deviance of the model along the regularization
#' path. It is computed from the slots `dev.ratio` and `nulldev` from the
#' `"sgdnet"` object using the formula
#'
#' \deqn{
#'   (1 - \mathtt{dev.ratio}) \times \mathtt{nulldev}
#' }{
#'   (1 - dev.ratio)*nulldev
#' }
#'
#' where `nulldev` is the deviance of the intercept-only model.
#'
#' @param object an object of class `'sgdnet'`
#' @param ... ignored
#'
#' @return The deviance of `object` at each value along the regularization path.
#'   For `family = "gaussian"` in [sgdnet()], this is the residual sum of
#'   squares.
#'
#' @export
#'
#' @seealso [stats::deviance()], [sgdnet()]
#'
#' @examples
#' fit <- sgdnet(wine$x, wine$y, family = "multinomial")
#' deviance(fit)
deviance.sgdnet <- function(object, ...) {
  (1 - object$dev.ratio)*object$nulldev
}

#' @export
#' @rdname deviance.sgdnet
deviance.cv_sgdnet <- function(object, ...) {
  stats::deviance(object$fit, ...)
}
jolars/sgdnet documentation built on May 22, 2019, 11:52 p.m.