@@ -30,7 +30,7 @@ check_residuals <- function(x, ...) {
30
30
31
31
# ' @export
32
32
check_residuals.default <- function (x , ... ) {
33
- insight :: format_error(" `check_residuals()` only works with objects returned by `simulate_residuals()` by `DHARMa::simulateResiduals()`." ) # nolint
33
+ insight :: format_error(" `check_residuals()` only works with objects returned by `simulate_residuals()` or `DHARMa::simulateResiduals()`." ) # nolint
34
34
}
35
35
36
36
# ' @rdname check_residuals
@@ -39,12 +39,22 @@ check_residuals.performance_simres <- function(x,
39
39
alternative = c(" two.sided" , " less" , " greater" ),
40
40
... ) {
41
41
alternative <- match.arg(alternative )
42
- stats :: ks.test(
43
- stats :: residuals(simulated_residuals ),
44
- " punif" ,
45
- alternative = alternative ,
46
- ...
42
+ ts <- suppressWarnings(
43
+ stats :: ks.test(
44
+ stats :: residuals(simulated_residuals ),
45
+ " punif" ,
46
+ alternative = alternative ,
47
+ ...
48
+ )
47
49
)
50
+
51
+ p.val <- ts $ p.value
52
+
53
+ attr(p.val , " data" ) <- x
54
+ attr(p.val , " object_name" ) <- insight :: safe_deparse_symbol(substitute(x ))
55
+ class(p.val ) <- unique(c(" check_residuals" , " see_check_residuals" , class(p.val )))
56
+
57
+ p.val
48
58
}
49
59
50
60
# ' @export
@@ -53,4 +63,25 @@ check_residuals.DHARMa <- check_residuals.performance_simres
53
63
54
64
# methods ------------------------------
55
65
56
- # TODO: Add print method
66
+ # ' @export
67
+ print.check_residuals <- function (x , ... ) {
68
+ pstring <- insight :: format_p(x )
69
+
70
+ if (x < 0.05 ) {
71
+ insight :: print_color(
72
+ sprintf(
73
+ " Warning: Non-uniformity of simulated residuals detected (%s).\n " , pstring
74
+ ),
75
+ " red"
76
+ )
77
+ } else {
78
+ insight :: print_color(
79
+ sprintf(
80
+ " OK: Simulated residuals appear as uniformly distributed (%s).\n " , pstring
81
+ ),
82
+ " green"
83
+ )
84
+ }
85
+
86
+ invisible (x )
87
+ }
0 commit comments