Skip to content

Commit

Permalink
new dev version
Browse files Browse the repository at this point in the history
  • Loading branch information
MHaringa committed Dec 23, 2022
1 parent 1ba04b9 commit 8ce689e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: insurancerating
Type: Package
Title: Analytic Insurance Rating Techniques
Version: 0.7.2
Version: 0.7.2.9000
Authors@R: c(person("Martin", "Haringa", role = c("aut", "cre"), email = "mtharinga@gmail.com"))
Maintainer: Martin Haringa <mtharinga@gmail.com>
BugReports: https://github.com/mharinga/insurancerating/issues
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Expand Up @@ -81,7 +81,6 @@ importFrom(grDevices,dev.off)
importFrom(grDevices,png)
importFrom(graphics,plot)
importFrom(insight,export_table)
importFrom(insight,print_color)
importFrom(lubridate,"%m+%")
importFrom(lubridate,ceiling_date)
importFrom(lubridate,days)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
@@ -1,3 +1,5 @@
# insurancerating 0.7.3

# insurancerating 0.7.2

* `update_glm()` now always returns the correct interval in case the function is used in combination with `smooth_coef()`
Expand Down
9 changes: 2 additions & 7 deletions R/model_performance.R
Expand Up @@ -91,21 +91,16 @@ model_performance <- function(...){


#' @importFrom insight export_table
#' @importFrom insight print_color
#' @export
print.model_performance <- function(x, digits = 3, ...) {
orig_x <- x
insight::print_color("# Comparison of Model Performance Indices\n\n", "blue")

cat(color_blue("# Comparison of Model Performance Indices\n\n"))
x[] <- lapply(x, function(i) { if (is.numeric(i)) {
round(i, digits = digits) } else { i } })
return(x)
cat(insight::export_table(x))
invisible(orig_x)
}







15 changes: 4 additions & 11 deletions R/model_performance_residuals.R
Expand Up @@ -26,7 +26,6 @@
#' @author Martin Haringa
#'
#' @importFrom DHARMa simulateResiduals
#' @importFrom insight print_color
#' @importFrom stats approx
#' @importFrom stats ks.test
#'
Expand Down Expand Up @@ -82,12 +81,9 @@ check_residuals <- function(object, n_simulations = 30){
print.check_residuals <- function(x, ...) {
p.val <- x$p.val
if (p.val < 0.05) {
insight::print_color(sprintf("Warning: deviations from the expected
distribution detected (p = %.3f).", p.val),
"red")
cat(color_red(sprintf("Warning: deviations from the expected distribution detected (p = %.3f).", p.val)))
} else {
insight::print_color(sprintf("OK: residuals appear as from the expected
distribution (p = %.3f).", p.val), "green")
cat(color_green(sprintf("OK: residuals appear as from the expected distribution (p = %.3f).", p.val)))
}
}

Expand All @@ -113,12 +109,9 @@ autoplot.check_residuals <- function(object, show_message = TRUE, ...) {
if ( isTRUE(show_message) ){
p.val <- object$p.val
if (p.val < 0.05) {
insight::print_color(sprintf("Warning: deviations from the expected
distribution detected (p = %.3f).", p.val),
"red")
cat(color_red(sprintf("Warning: deviations from the expected distribution detected (p = %.3f).", p.val)))
} else {
insight::print_color(sprintf("OK: residuals appear as from the expected
distribution (p = %.3f).", p.val), "green")
cat(color_green(sprintf("OK: residuals appear as from the expected distribution (p = %.3f).", p.val)))
}
}
dat <- object$df
Expand Down
21 changes: 21 additions & 0 deletions R/utils.R
Expand Up @@ -609,3 +609,24 @@ ptrunc <- function( q, spec, a = -Inf, b = Inf, ... )
return( result )
}

#' @keywords internal
color_blue <- function(x){
x[!is.na(x)] <- paste0("\033[", "3", "4m", x[!is.na(x)],
"\033[", "3", "9m")
x
}


#' @keywords internal
color_red <- function(x){
x[!is.na(x)] <- paste0("\033[", "3", "1m", x[!is.na(x)],
"\033[", "3", "9m")
x
}

#' @keywords internal
color_green <- function(x){
x[!is.na(x)] <- paste0("\033[", "3", "2m", x[!is.na(x)],
"\033[", "3", "9m")
x
}

0 comments on commit 8ce689e

Please sign in to comment.