|
48 | 48 | fun_args[["robust"]] <- NULL |
49 | 49 | fun <- datawizard::standardize |
50 | 50 | model <- do.call(fun, fun_args) |
| 51 | + standardize <- NULL |
51 | 52 | } |
52 | 53 |
|
53 | 54 | parameters <- insight::get_parameters( |
|
290 | 291 |
|
291 | 292 | # ==== Std Coefficients for other methods than "refit" |
292 | 293 |
|
293 | | - if (!is.null(standardize) && !isTRUE(standardize == "refit")) { |
| 294 | + if (!is.null(standardize)) { |
294 | 295 | # give minimal attributes required for standardization |
295 | 296 | temp_pars <- parameters |
296 | 297 | class(temp_pars) <- c("parameters_model", class(temp_pars)) |
|
775 | 776 | verbose = TRUE, |
776 | 777 | ... |
777 | 778 | ) { |
| 779 | + if ( |
| 780 | + isTRUE(test == "all") && (!is.null(standardize) || insight::is_multivariate(model)) |
| 781 | + ) { |
| 782 | + exception_type <- ifelse( |
| 783 | + is.null(standardize), |
| 784 | + "for multivariate models", |
| 785 | + "when standardizing" |
| 786 | + ) |
| 787 | + insight::format_error( |
| 788 | + sprintf("`test = \"all\"` is not supported %s;", exception_type), |
| 789 | + "Please specify the tests you want to perform using the `test` argument." |
| 790 | + ) |
| 791 | + } |
| 792 | + |
| 793 | + # No scale-dependent inferential statistics |
| 794 | + if ( |
| 795 | + !is.null(standardize) && |
| 796 | + any( |
| 797 | + c( |
| 798 | + "bf", |
| 799 | + "bayesfactor", |
| 800 | + "bayes_factor", |
| 801 | + "rope", |
| 802 | + "p_rope", |
| 803 | + "equivalence_test", |
| 804 | + "equitest" |
| 805 | + ) %in% |
| 806 | + test |
| 807 | + ) |
| 808 | + ) { |
| 809 | + test <- setdiff( |
| 810 | + test, |
| 811 | + c( |
| 812 | + "bf", |
| 813 | + "bayesfactor", |
| 814 | + "bayes_factor", |
| 815 | + "rope", |
| 816 | + "p_rope", |
| 817 | + "equivalence_test", |
| 818 | + "equitest" |
| 819 | + ) |
| 820 | + ) |
| 821 | + if (verbose) { |
| 822 | + insight::format_warning( |
| 823 | + "Scale-dependent inferential statistics (such as `rope` and `bayes_factor`) are not meaningful for standardized parameters", |
| 824 | + "These have been removed from the output." |
| 825 | + ) |
| 826 | + } |
| 827 | + } |
| 828 | + |
778 | 829 | # no ROPE for multi-response models |
779 | 830 | if (insight::is_multivariate(model) && any(c("rope", "p_rope") %in% test)) { |
780 | 831 | test <- setdiff(test, c("rope", "p_rope")) |
781 | 832 | if (verbose) { |
782 | | - insight::format_alert( |
| 833 | + insight::format_warning( |
783 | 834 | "Multivariate response models are not yet supported for tests `rope` and `p_rope`." |
784 | 835 | ) |
785 | 836 | } |
786 | 837 | } |
787 | 838 |
|
| 839 | + if (length(test) == 0) { |
| 840 | + test <- NULL |
| 841 | + } |
| 842 | + |
| 843 | + if (isTRUE(standardize == "refit")) { |
| 844 | + model <- datawizard::standardize(model, verbose = verbose) |
| 845 | + standardize <- NULL |
| 846 | + } |
| 847 | + |
788 | 848 | # MCMCglmm need special handling |
789 | 849 | if (inherits(model, "MCMCglmm")) { |
790 | 850 | parameters <- bayestestR::describe_posterior( |
|
816 | 876 | verbose = verbose, |
817 | 877 | ... |
818 | 878 | ) |
| 879 | + } |
819 | 880 |
|
820 | | - if (!is.null(standardize)) { |
821 | | - # Don't test BF on standardized params |
822 | | - test_no_BF <- test[!test %in% c("bf", "bayesfactor", "bayes_factor")] |
823 | | - if (length(test_no_BF) == 0) { |
824 | | - test_no_BF <- NULL |
825 | | - } |
826 | | - std_post <- standardize_posteriors(model, method = standardize) |
827 | | - std_parameters <- bayestestR::describe_posterior( |
828 | | - std_post, |
829 | | - centrality = centrality, |
830 | | - dispersion = dispersion, |
831 | | - ci = ci, |
832 | | - ci_method = ci_method, |
833 | | - test = test_no_BF, |
834 | | - rope_range = rope_range, |
835 | | - rope_ci = rope_ci, |
836 | | - verbose = verbose, |
837 | | - ... |
838 | | - ) |
| 881 | + if (!is.null(standardize)) { |
| 882 | + # give minimal attributes required for standardization |
| 883 | + temp_pars <- parameters |
| 884 | + class(temp_pars) <- c("parameters_model", class(temp_pars)) |
| 885 | + attr(temp_pars, "ci") <- ci |
| 886 | + attr(temp_pars, "object_name") <- model # pass the model as is (this is a cheat - teehee!) |
839 | 887 |
|
840 | | - parameters <- merge( |
841 | | - std_parameters, |
842 | | - parameters[c( |
843 | | - "Parameter", |
844 | | - setdiff(colnames(parameters), colnames(std_parameters)) |
845 | | - )], |
846 | | - sort = FALSE |
847 | | - ) |
848 | | - } |
| 888 | + std_parameters <- standardize_parameters(temp_pars, method = standardize) |
| 889 | + |
| 890 | + parameters <- merge( |
| 891 | + std_parameters, |
| 892 | + parameters[c("Parameter", setdiff(colnames(parameters), colnames(std_parameters)))], |
| 893 | + sort = FALSE |
| 894 | + ) |
| 895 | + |
| 896 | + parameters <- .NA_inferential_cols(parameters) |
849 | 897 | } |
850 | 898 |
|
851 | 899 | if (length(ci) > 1) { |
|
1057 | 1105 | .NA_inferential_cols <- function(pr) { |
1058 | 1106 | # For models where the response is NOT standardized, the (Intercept) is set |
1059 | 1107 | # to NA and so we also need to set all inferential statistics to NA |
1060 | | - rows_to_NA <- pr$Parameter %in% "(Intercept)" | is.na(pr$Std_Coefficient) |
| 1108 | + coef_name <- colnames(pr)[startsWith(colnames(pr), "Std_")] |
| 1109 | + if (length(coef_name) != 1L) { |
| 1110 | + insight::format_error("Wrong number of standardized coefficient columns detected.") |
| 1111 | + } |
| 1112 | + rows_to_NA <- pr$Parameter == "(Intercept)" | is.na(pr[[coef_name]]) |
1061 | 1113 | if (any(rows_to_NA)) { |
1062 | 1114 | # fmt: skip |
1063 | 1115 | cols_not_to_NA <- c(".id", "Parameter", "Component", "Response", "Effects", "Group", |
1064 | | - "CI", "Std_Coefficient") |
| 1116 | + "CI", coef_name) |
1065 | 1117 | cols_to_NA <- setdiff(colnames(pr), cols_not_to_NA) |
1066 | 1118 | pr[rows_to_NA, cols_to_NA] <- NA |
1067 | 1119 | } |
|
0 commit comments