1
#' Extract residuals from an mkinfit model
2
#'
3
#' @param object A \code{\link{mkinfit}} object
4
#' @param standardized Should the residuals be standardized by dividing by the
5
#'   standard deviation obtained from the fitted error model?
6
#' @param \dots Not used
7
#' @export
8
#' @examples
9
#' f <- mkinfit("DFOP", FOCUS_2006_C, quiet = TRUE)
10
#' residuals(f)
11
#' residuals(f, standardized = TRUE)
12
residuals.mkinfit <- function(object, standardized = FALSE, ...) {
13 2
  res <- object$data[["residual"]]
14 2
  if (standardized) {
15 2
    if (object$err_mod == "const") {
16 2
      sigma_fitted <- object$errparms["sigma"]
17
    }
18 2
    if (object$err_mod == "obs") {
19 2
      sigma_names = paste0("sigma_", object$data[["variable"]])
20 2
      sigma_fitted <- object$errparms[sigma_names]
21
    }
22 2
    if (object$err_mod == "tc") {
23 2
      sigma_fitted <- sigma_twocomp(object$data[["predicted"]],
24 2
        sigma_low = object$errparms[1],
25 2
        rsd_high = object$errparms[2])
26
    }
27 2
    return(res / sigma_fitted)
28
  }
29 2
  return(res)
30
}
31

Read our documentation on viewing source code .

Loading