diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2019-10-31 01:55:01 +0100 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2019-10-31 01:59:05 +0100 |
commit | 7091d3738e7e55acb20edb88772b228f6f5b6c98 (patch) | |
tree | b6e31700074605c702662e5238162c57de330453 /R/residuals.mkinfit.R | |
parent | 5e4ea59a41e00b05ea6664c08c7922e892e8ab77 (diff) |
Add likelihood ratio test and other methods, fixes
The likelihood ratio test method is lrtest, in addition,
methods for update and residuals were added.
Diffstat (limited to 'R/residuals.mkinfit.R')
-rw-r--r-- | R/residuals.mkinfit.R | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/R/residuals.mkinfit.R b/R/residuals.mkinfit.R new file mode 100644 index 00000000..96bcf01c --- /dev/null +++ b/R/residuals.mkinfit.R @@ -0,0 +1,31 @@ +#' Extract residuals from an mkinfit model +#' +#' @param object An \code{\link{mkinfit}} object +#' @param standardized Should the residuals be standardized by dividing by the +#' standard deviation obtained from the fitted error model? +#' @param \dots Not used +#' @export +#' @examples +#' f <- mkinfit("DFOP", FOCUS_2006_C, quiet = TRUE) +#' residuals(f) +#' residuals(f, standardized = TRUE) +residuals.mkinfit <- function(object, standardized = FALSE, ...) { + res <- object$data[["residual"]] + if (standardized) { + if (object$err_mod == "const") { + sigma_fitted <- object$errparms["sigma"] + } + if (object$err_mod == "obs") { + sigma_names = paste0("sigma_", object$data[["variable"]]) + sigma_fitted <- object$errparms[sigma_names] + } + if (object$err_mod == "tc") { + sigma_fitted <- sigma_twocomp(object$data[["predicted"]], + sigma_low = object$errparms[1], + rsd_high = object$errparms[2]) + } + return(res / sigma_fitted) + } + return(res) +} + |