|
4 | 4 | #' @description `check_convergence()` provides an alternative convergence |
5 | 5 | #' test for `merMod`-objects. |
6 | 6 | #' |
7 | | -#' @param x A `merMod`-object. |
8 | | -#' @param tolerance Indicates up to which value the convergence result is |
9 | | -#' accepted. The smaller `tolerance` is, the stricter the test |
10 | | -#' will be. |
11 | | -#' @param ... Currently not used. |
| 7 | +#' @inheritParams insight::is_converged |
12 | 8 | #' |
13 | 9 | #' @return `TRUE` if convergence is fine and `FALSE` if convergence |
14 | 10 | #' is suspicious. Additionally, the convergence value is returned as attribute. |
|
63 | 59 | #' } |
64 | 60 | #' @export |
65 | 61 | check_convergence <- function(x, tolerance = 0.001, ...) { |
66 | | - UseMethod("check_convergence") |
67 | | -} |
68 | | - |
69 | | - |
70 | | -#' @export |
71 | | -check_convergence.default <- function(x, tolerance = 0.001, ...) { |
72 | | - insight::print_color(sprintf("check_convergence() does not work for models of class '%s'.\n", class(x)[1]), "red") |
73 | | -} |
74 | | - |
75 | | - |
76 | | -#' @export |
77 | | -check_convergence.merMod <- function(x, tolerance = 0.001, ...) { |
78 | | - insight::check_if_installed("Matrix") |
79 | | - |
80 | | - relgrad <- with(x@optinfo$derivs, Matrix::solve(Hessian, gradient)) |
81 | | - |
82 | | - # copy logical value, TRUE if convergence is OK |
83 | | - retval <- max(abs(relgrad)) < tolerance |
84 | | - # copy convergence value |
85 | | - attr(retval, "gradient") <- max(abs(relgrad)) |
86 | | - |
87 | | - # return result |
88 | | - retval |
| 62 | + insight::is_converged(x, tolerance = tolerance, ...) |
89 | 63 | } |
0 commit comments