deviance.R 2.19 KB
Newer Older
Tom Reynkens's avatar
Tom Reynkens committed
1 2 3 4 5 6 7 8 9 10 11 12
###############################################
#
# Model deviance
#
###############################################


#' @export
#' @title Deviance of Estimated Model
#' 
#' @description Function to extract the deviance of the estimated model.
#' 
13
#' @param object An object of class '\code{\link[=glmsmurf-class]{glmsmurf}}', typically the result of a call to \code{\link{glmsmurf}} or \code{\link{glmsmurf.fit}}.
Tom Reynkens's avatar
Tom Reynkens committed
14 15 16 17 18
#' @param ... Additional arguments which are currently ignored.
#' 
#' @return The deviance of the estimated model in \code{object}.
#' 
#' @seealso \code{\link{deviance_reest}}, \code{\link[stats]{deviance}}, \code{\link{summary.glmsmurf}}, 
19
#'          \code{\link{glmsmurf}}, \code{\link{glmsmurf-class}}
Tom Reynkens's avatar
Tom Reynkens committed
20
#'          
21 22
#'
#' @examples ## See example(glmsmurf) for examples
Tom Reynkens's avatar
Tom Reynkens committed
23 24 25 26 27 28 29 30 31 32 33 34 35
#'          
deviance.glmsmurf <- function(object, ...) {
  
  return(object$deviance)
}


#' @export
#' @title Deviance of Re-estimated Model
#' 
#' @description Function to extract the deviance of the re-estimated model.
#' 
#' @param object An object for which the extraction of the deviance is meaningful. 
36
#'               E.g. an object of class '\code{\link[=glmsmurf-class]{glmsmurf}}', typically the result of a call to \code{\link{glmsmurf}} or \code{\link{glmsmurf.fit}}.
Tom Reynkens's avatar
Tom Reynkens committed
37 38 39 40 41 42
#' @inheritParams deviance.glmsmurf
#' 
#' @return The deviance of the re-estimated model in \code{object}, 
#'         when it is available or, otherwise, the deviance of the estimated model in \code{object} with a warning.
#' 
#' @seealso \code{\link{deviance.glmsmurf}}, \code{\link[stats]{deviance}}, \code{\link{summary.glmsmurf}}, 
43
#'          \code{\link{glmsmurf}}, \code{\link{glmsmurf-class}}
Tom Reynkens's avatar
Tom Reynkens committed
44
#' 
45
#' @examples ## See example(glmsmurf) for examples
Tom Reynkens's avatar
Tom Reynkens committed
46 47 48 49 50 51 52 53 54
#'    
deviance_reest <- function(object, ...) UseMethod("deviance_reest", object)


#' @export
#' @rdname deviance_reest
deviance_reest.glmsmurf <- function(object, ...) {
  
  if (!exists("deviance.reest", object)) {
55
    warning("Deviance of the re-estimated model is not present in 'object', deviance of the estimated model is used.")
Tom Reynkens's avatar
Tom Reynkens committed
56 57 58 59 60 61 62 63 64
    
    # Return deviance of estimated model
    return(object$deviance)
    
  } else {
    # Return deviance of re-estimated model
    return(object$deviance.reest)
  }
}