@@ -355,6 +355,98 @@ equivalence_test.glmmTMB <- equivalence_test.merMod
355355equivalence_test.MixMod <- equivalence_test.merMod
356356
357357
358+ # modelbased ------------------------------
359+
360+ # ' @export
361+ equivalence_test.estimate_means <- function (
362+ x ,
363+ range = " default" ,
364+ ci = 0.95 ,
365+ rule = " classic" ,
366+ vcov = NULL ,
367+ vcov_args = NULL ,
368+ verbose = TRUE ,
369+ ...
370+ ) {
371+ # ==== define rope range ====
372+
373+ range <- .check_rope_range(x , range , verbose )
374+
375+ if (length(ci ) > 1 ) {
376+ insight :: format_alert(" `ci` may only be of length 1. Using first ci-value now." )
377+ ci <- ci [1 ]
378+ }
379+
380+ # ==== check degrees of freedom ====
381+
382+ dof <- unique(insight :: get_df(x ))
383+ if (length(dof ) > 1 ) {
384+ dof <- Inf
385+ }
386+
387+ # ==== requested confidence intervals ====
388+
389+ conf_int <- as.data.frame(t(x [c(" CI_low" , " CI_high" )]))
390+
391+ # ==== the "narrower" intervals (1-2*alpha) for CET-rules. ====
392+
393+ alpha <- 1 - ci
394+ insight :: check_if_installed(" modelbased" )
395+
396+ # we need to call the modelbased function again, so get the call
397+ # modify CI and evaluate that call
398+ cl <- insight :: get_call(x )
399+ cl $ ci <- ci - alpha
400+ x2 <- eval(cl )
401+ conf_int2 <- as.data.frame(t(x2 [c(" CI_low" , " CI_high" )]))
402+
403+ # ==== equivalence test for each parameter ====
404+
405+ l <- Map(
406+ function (ci_wide , ci_narrow ) {
407+ .equivalence_test_numeric(
408+ ci = ci ,
409+ ci_wide ,
410+ ci_narrow ,
411+ range_rope = range ,
412+ rule = rule ,
413+ dof = dof ,
414+ verbose = verbose
415+ )
416+ },
417+ conf_int ,
418+ conf_int2
419+ )
420+
421+ dat <- do.call(rbind , l )
422+ params <- insight :: get_parameters(x )
423+
424+ out <- data.frame (
425+ Parameter = params $ Parameter ,
426+ CI = ifelse(rule == " bayes" , ci , ci - alpha ),
427+ dat ,
428+ stringsAsFactors = FALSE
429+ )
430+
431+ # ==== (adjusted) p-values for tests ====
432+
433+ out $ p <- .add_p_to_equitest(x , ci , range , vcov = vcov , vcov_args = vcov_args , ... )
434+
435+ attr(out , " rope" ) <- range
436+ attr(out , " object_name" ) <- insight :: safe_deparse_symbol(substitute(x ))
437+ attr(out , " rule" ) <- rule
438+ class(out ) <- c(" equivalence_test_lm" , " see_equivalence_test_lm" , class(out ))
439+
440+ out
441+ }
442+
443+ # ' @export
444+ equivalence_test.estimate_contrasts <- equivalence_test.estimate_means
445+
446+ # ' @export
447+ equivalence_test.estimate_slopes <- equivalence_test.estimate_means
448+
449+
358450# Special classes -------------------------
359451
360452# ' @export
@@ -407,6 +499,14 @@ equivalence_test.parameters_model <- function(x,
407499
408500# ' @keywords internal
409501.check_rope_range <- function (x , range , verbose ) {
502+ # for modelbased-objects, we extract the model to define the rope range
503+ if (inherits(x , c(" estimate_means" , " estimate_contrasts" , " estimate_slopes" ))) {
504+ x <- .safe(insight :: get_model(x ))
505+ # if not successful, return defaults
506+ if (is.null(x )) {
507+ return (c(- 1 , 1 ))
508+ }
509+ }
410510 if (all(range == " default" )) {
411511 range <- bayestestR :: rope_range(x , verbose = verbose )
412512 if (is.list(range )) {
@@ -439,7 +539,6 @@ equivalence_test.parameters_model <- function(x,
439539 ci <- ci [1 ]
440540 }
441541
442-
443542 # ==== check degrees of freedom ====
444543
445544 df_column <- grep(" (df|df_error)" , colnames(x ))
0 commit comments