aboutsummaryrefslogtreecommitdiff
path: root/R/illparms.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2022-07-21 17:15:12 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2022-07-21 17:43:16 +0200
commitb703ee38ffc8877be843cf5a557dd9c32c54f977 (patch)
tree4da8adf610a1e431f514efc256f44bb7abdec4ca /R/illparms.R
parentad6ef5013dce7ef1ef9bbcadbd278b71da9b6f72 (diff)
Summary method for mmkin objects
Also, add a method for gathering convergence information and a method for gathering information on ill-defined parameters
Diffstat (limited to 'R/illparms.R')
-rw-r--r--R/illparms.R62
1 files changed, 62 insertions, 0 deletions
diff --git a/R/illparms.R b/R/illparms.R
new file mode 100644
index 00000000..f23f1cae
--- /dev/null
+++ b/R/illparms.R
@@ -0,0 +1,62 @@
+#' Method to get the names of ill-defined parameters
+#'
+#' @param object The object to investigate
+#' @param x The object to be printed
+#' @param conf.level The confidence level for checking p values
+#' @param \dots For potential future extensions
+#' @return For [mkinfit] objects, a character vector of parameter names
+#' For [mmkin] objects, an object of class 'illparms.mmkin' with a
+#' suitable printing method.
+#' @export
+illparms <- function(object, ...)
+{
+ UseMethod("illparms", object)
+}
+
+#' @rdname illparms
+#' @export
+#' @examples
+#' fit <- mkinfit("FOMC", FOCUS_2006_A, quiet = TRUE)
+#' illparms(fit)
+illparms.mkinfit <- function(object, conf.level = 0.95, ...) {
+ p_values <- suppressWarnings(summary(object)$bpar[, "Pr(>t)"])
+ na <- is.na(p_values)
+ failed <- p_values > 1 - conf.level
+ names(parms(object))[na | failed]
+}
+
+#' @rdname illparms
+#' @export
+#' @examples
+#' \dontrun{
+#' fits <- mmkin(
+#' c("SFO", "FOMC"),
+#' list("FOCUS A" = FOCUS_2006_A,
+#' "FOCUS C" = FOCUS_2006_C),
+#' quiet = TRUE)
+#' illparms(fits)
+#' }
+illparms.mmkin <- function(object, conf.level = 0.95, ...) {
+ result <- lapply(object,
+ function(fit) {
+ if (inherits(fit, "try-error")) return("E")
+ ill <- illparms(fit, conf.level = conf.level)
+ if (length(ill) > 0) {
+ return(paste(ill, collapse = ", "))
+ } else {
+ return("")
+ }
+ })
+ result <- unlist(result)
+ dim(result) <- dim(object)
+ dimnames(result) <- dimnames(object)
+ class(result) <- "illparms.mmkin"
+ return(result)
+}
+
+#' @rdname illparms
+#' @export
+print.illparms.mmkin <- function(x, ...) {
+ class(x) <- NULL
+ print(x, quote = FALSE)
+}

Contact - Imprint