diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index abb3c037a..4a0f8ec1b 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ -Version: 0.12.2 -Date: 2024-07-17 21:02:38 UTC -SHA: d4c45126ca666644785dc64d2af6b87eee9ca39b +Version: 0.12.3 +Date: 2024-09-02 16:10:51 UTC +SHA: dfbe03fd4961ee9049d5169275248a4ef7a5a21e diff --git a/DESCRIPTION b/DESCRIPTION index 593afc5b1..bf2622588 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.12.2.13 +Version: 0.12.3 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -160,4 +160,3 @@ Config/Needs/website: r-lib/pkgdown, easystats/easystatstemplate Config/rcmdcheck/ignore-inconsequential-notes: true -Remotes: easystats/see, easystats/insight diff --git a/NAMESPACE b/NAMESPACE index 67add6a04..08f6bcc15 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -170,12 +170,14 @@ S3method(model_performance,censReg) S3method(model_performance,clm) S3method(model_performance,clm2) S3method(model_performance,coxph) +S3method(model_performance,coxph_weightit) S3method(model_performance,default) S3method(model_performance,felm) S3method(model_performance,fixest) S3method(model_performance,fixest_multi) S3method(model_performance,flexsurvreg) S3method(model_performance,glm) +S3method(model_performance,glm_weightit) S3method(model_performance,glmmTMB) S3method(model_performance,glmmadmb) S3method(model_performance,glmx) @@ -197,9 +199,11 @@ S3method(model_performance,mixor) S3method(model_performance,mlogit) S3method(model_performance,model_fit) S3method(model_performance,multinom) +S3method(model_performance,multinom_weightit) S3method(model_performance,negbinirr) S3method(model_performance,negbinmfx) S3method(model_performance,nestedLogit) +S3method(model_performance,ordinal_weightit) S3method(model_performance,plm) S3method(model_performance,poissonirr) S3method(model_performance,poissonmfx) diff --git a/R/check_dag.R b/R/check_dag.R index 0a6411056..dcfe8f33c 100644 --- a/R/check_dag.R +++ b/R/check_dag.R @@ -103,7 +103,7 @@ #' Interpreting Confounder and Modifier Coefficients. American Journal of #' Epidemiology, 177(4), 292–298. \doi{10.1093/aje/kws412} #' -#' @examplesIf require("ggdag", quietly = TRUE) && require("dagitty", quietly = TRUE) && require("see", quietly = TRUE) +#' @examplesIf require("ggdag", quietly = TRUE) && require("dagitty", quietly = TRUE) && require("see", quietly = TRUE) && packageVersion("see") > "0.8.5" #' # no adjustment needed #' check_dag( #' y ~ x + b, diff --git a/R/check_singularity.R b/R/check_singularity.R index e2e369f61..86de4fcce 100644 --- a/R/check_singularity.R +++ b/R/check_singularity.R @@ -97,6 +97,7 @@ #' ) #' check_singularity(model) #' +#' \dontrun{ #' # Fixing singularity issues using priors in glmmTMB #' # Example taken from `vignette("priors", package = "glmmTMB")` #' dat <- readRDS(system.file( @@ -120,7 +121,7 @@ #' model_with_priors <- update(model, priors = prior) #' # no singular fit #' check_singularity(model_with_priors) -#' +#' } #' @export check_singularity <- function(x, tolerance = 1e-5, ...) { UseMethod("check_singularity") diff --git a/R/model_performance.lm.R b/R/model_performance.lm.R index c797b396f..0199b4ce4 100644 --- a/R/model_performance.lm.R +++ b/R/model_performance.lm.R @@ -3,10 +3,10 @@ #' Compute indices of model performance for regression models. #' #' @param model A model. -#' @param metrics Can be `"all"`, `"common"` or a character vector of -#' metrics to be computed (one or more of `"AIC"`, `"AICc"`, `"BIC"`, `"R2"`, -#' `"R2_adj"`, `"RMSE"`, `"SIGMA"`, `"LOGLOSS"`, `"PCP"`, `"SCORE"`). -#' `"common"` will compute AIC, BIC, R2 and RMSE. +#' @param metrics Can be `"all"`, `"common"` or a character vector of metrics to +#' be computed (one or more of `"AIC"`, `"AICc"`, `"BIC"`, `"R2"`, `"R2_adj"`, +#' `"RMSE"`, `"SIGMA"`, `"LOGLOSS"`, `"PCP"`, `"SCORE"`). `"common"` will +#' compute AIC, BIC, R2 and RMSE. #' @param verbose Toggle off warnings. #' @param ... Arguments passed to or from other methods. #' @@ -209,6 +209,18 @@ model_performance.lm_robust <- model_performance.lm #' @export model_performance.multinom <- model_performance.lm +#' @export +model_performance.multinom_weightit <- model_performance.lm + +#' @export +model_performance.ordinal_weightit <- model_performance.lm + +#' @export +model_performance.coxph_weightit <- model_performance.lm + +#' @export +model_performance.glm_weightit <- model_performance.lm + #' @export model_performance.plm <- model_performance.lm diff --git a/R/r2.R b/R/r2.R index aeddd56ce..d62a0c477 100644 --- a/R/r2.R +++ b/R/r2.R @@ -251,7 +251,6 @@ r2.aov <- function(model, ci = NULL, ...) { #' @rdname r2 #' @export r2.mlm <- function(model, multivariate = TRUE, ...) { - if (multivariate) { out <- r2_mlm(model) } else { diff --git a/R/r2_coxsnell.R b/R/r2_coxsnell.R index 3db7197b7..36df504ec 100644 --- a/R/r2_coxsnell.R +++ b/R/r2_coxsnell.R @@ -8,12 +8,12 @@ #' @param ... Currently not used. #' #' @details -#' This index was proposed by *Cox and Snell (1989, pp. 208-9)* and, -#' apparently independently, by *Magee (1990)*; but had been suggested -#' earlier for binary response models by *Maddala (1983)*. However, this -#' index achieves a maximum of less than 1 for discrete models (i.e. models -#' whose likelihood is a product of probabilities) which have a maximum of 1, -#' instead of densities, which can become infinite *(Nagelkerke, 1991)*. +#' This index was proposed by *Cox and Snell (1989, pp. 208-9)* and, apparently +#' independently, by *Magee (1990)*; but had been suggested earlier for binary +#' response models by *Maddala (1983)*. However, this index achieves a maximum +#' of less than 1 for discrete models (i.e. models whose likelihood is a product +#' of probabilities) which have a maximum of 1, instead of densities, which can +#' become infinite *(Nagelkerke, 1991)*. #' #' @return A named vector with the R2 value. #' @@ -24,12 +24,12 @@ #' @references #' - Cox, D. R., Snell, E. J. (1989). Analysis of binary data (Vol. 32). #' Monographs on Statistics and Applied Probability. -#' - Magee, L. (1990). R 2 measures based on Wald and likelihood ratio -#' joint significance tests. The American Statistician, 44(3), 250-253. +#' - Magee, L. (1990). R 2 measures based on Wald and likelihood ratio joint +#' significance tests. The American Statistician, 44(3), 250-253. #' - Maddala, G. S. (1986). Limited-dependent and qualitative variables in #' econometrics (No. 3). Cambridge university press. -#' - Nagelkerke, N. J. (1991). A note on a general definition of the -#' coefficient of determination. Biometrika, 78(3), 691-692. +#' - Nagelkerke, N. J. (1991). A note on a general definition of the coefficient +#' of determination. Biometrika, 78(3), 691-692. #' #' @export r2_coxsnell <- function(model, ...) { diff --git a/R/r2_mlm.R b/R/r2_mlm.R index 0f08ad235..240701439 100644 --- a/R/r2_mlm.R +++ b/R/r2_mlm.R @@ -53,7 +53,7 @@ #' - Azen, R., & Budescu, D. V. (2006). Comparing predictors in #' multivariate regression models: An extension of dominance analysis. #' Journal of Educational and Behavioral Statistics, 31(2), 157-180. -#'- Cramer, E. M., & Nicewander, W. A. (1979). Some symmetric, +#' - Cramer, E. M., & Nicewander, W. A. (1979). Some symmetric, #' invariant measures of multivariate association. Psychometrika, 44, 43-54. #' - Van den Burg, W., & Lewis, C. (1988). Some properties of two #' measures of multivariate association. Psychometrika, 53, 109-122. @@ -73,7 +73,7 @@ r2_mlm.mlm <- function(model, verbose = TRUE, ...) { insight::get_predictors(model), insight::get_response(model) )$cor^2 - R_xy <- 1 - Reduce(`*`, rho2_vec, 1) + R_xy <- 1 - Reduce(`*`, rho2_vec, 1) resid_cov <- stats::cov(residuals(model)) resp_cov <- stats::cov(insight::get_response(model)) diff --git a/cran-comments.md b/cran-comments.md index 0fbbade1c..abc3f9611 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1 +1 @@ -This is a patch release that fixes failing CRAN checks for Mac OS old-rel. +Maintance release. diff --git a/man/check_dag.Rd b/man/check_dag.Rd index 266a62ec7..c33444f60 100644 --- a/man/check_dag.Rd +++ b/man/check_dag.Rd @@ -129,7 +129,7 @@ adjustments or over-adjustment. } \examples{ -\dontshow{if (require("ggdag", quietly = TRUE) && require("dagitty", quietly = TRUE) && require("see", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("ggdag", quietly = TRUE) && require("dagitty", quietly = TRUE) && require("see", quietly = TRUE) && packageVersion("see") > "0.8.5") (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # no adjustment needed check_dag( y ~ x + b, diff --git a/man/check_singularity.Rd b/man/check_singularity.Rd index cfe2dca0c..49015d0c7 100644 --- a/man/check_singularity.Rd +++ b/man/check_singularity.Rd @@ -92,6 +92,7 @@ model <- lme4::lmer( ) check_singularity(model) +\dontrun{ # Fixing singularity issues using priors in glmmTMB # Example taken from `vignette("priors", package = "glmmTMB")` dat <- readRDS(system.file( @@ -115,6 +116,7 @@ prior <- data.frame( model_with_priors <- update(model, priors = prior) # no singular fit check_singularity(model_with_priors) +} \dontshow{\}) # examplesIf} } \references{ diff --git a/man/model_performance.lm.Rd b/man/model_performance.lm.Rd index 208d9b1c4..11a820fff 100644 --- a/man/model_performance.lm.Rd +++ b/man/model_performance.lm.Rd @@ -9,10 +9,10 @@ \arguments{ \item{model}{A model.} -\item{metrics}{Can be \code{"all"}, \code{"common"} or a character vector of -metrics to be computed (one or more of \code{"AIC"}, \code{"AICc"}, \code{"BIC"}, \code{"R2"}, -\code{"R2_adj"}, \code{"RMSE"}, \code{"SIGMA"}, \code{"LOGLOSS"}, \code{"PCP"}, \code{"SCORE"}). -\code{"common"} will compute AIC, BIC, R2 and RMSE.} +\item{metrics}{Can be \code{"all"}, \code{"common"} or a character vector of metrics to +be computed (one or more of \code{"AIC"}, \code{"AICc"}, \code{"BIC"}, \code{"R2"}, \code{"R2_adj"}, +\code{"RMSE"}, \code{"SIGMA"}, \code{"LOGLOSS"}, \code{"PCP"}, \code{"SCORE"}). \code{"common"} will +compute AIC, BIC, R2 and RMSE.} \item{verbose}{Toggle off warnings.} diff --git a/man/r2_coxsnell.Rd b/man/r2_coxsnell.Rd index 2d53cb628..55dfaac1a 100644 --- a/man/r2_coxsnell.Rd +++ b/man/r2_coxsnell.Rd @@ -18,12 +18,12 @@ A named vector with the R2 value. Calculates the pseudo-R2 value based on the proposal from \emph{Cox & Snell (1989)}. } \details{ -This index was proposed by \emph{Cox and Snell (1989, pp. 208-9)} and, -apparently independently, by \emph{Magee (1990)}; but had been suggested -earlier for binary response models by \emph{Maddala (1983)}. However, this -index achieves a maximum of less than 1 for discrete models (i.e. models -whose likelihood is a product of probabilities) which have a maximum of 1, -instead of densities, which can become infinite \emph{(Nagelkerke, 1991)}. +This index was proposed by \emph{Cox and Snell (1989, pp. 208-9)} and, apparently +independently, by \emph{Magee (1990)}; but had been suggested earlier for binary +response models by \emph{Maddala (1983)}. However, this index achieves a maximum +of less than 1 for discrete models (i.e. models whose likelihood is a product +of probabilities) which have a maximum of 1, instead of densities, which can +become infinite \emph{(Nagelkerke, 1991)}. } \examples{ model <- glm(vs ~ wt + mpg, data = mtcars, family = "binomial") @@ -34,11 +34,11 @@ r2_coxsnell(model) \itemize{ \item Cox, D. R., Snell, E. J. (1989). Analysis of binary data (Vol. 32). Monographs on Statistics and Applied Probability. -\item Magee, L. (1990). R 2 measures based on Wald and likelihood ratio -joint significance tests. The American Statistician, 44(3), 250-253. +\item Magee, L. (1990). R 2 measures based on Wald and likelihood ratio joint +significance tests. The American Statistician, 44(3), 250-253. \item Maddala, G. S. (1986). Limited-dependent and qualitative variables in econometrics (No. 3). Cambridge university press. -\item Nagelkerke, N. J. (1991). A note on a general definition of the -coefficient of determination. Biometrika, 78(3), 691-692. +\item Nagelkerke, N. J. (1991). A note on a general definition of the coefficient +of determination. Biometrika, 78(3), 691-692. } } diff --git a/tests/testthat/test-check_heterogeneity_bias.R b/tests/testthat/test-check_heterogeneity_bias.R index 429dcfc0c..e01ecf3ff 100644 --- a/tests/testthat/test-check_heterogeneity_bias.R +++ b/tests/testthat/test-check_heterogeneity_bias.R @@ -32,3 +32,19 @@ test_that("check_heterogeneity_bias", { "Possible heterogeneity bias due to following predictors: Petal\\.Length, Petal\\.Width, Species" ) }) + +test_that("check_heterogeneity_bias", { + skip_if_not_installed("datawizard", minimum_version = "0.12.3") + data(efc, package = "datawizard") + dat <- na.omit(efc) + dat$e42dep <- factor(dat$e42dep) + dat$c172code <- factor(dat$c172code) + + out <- check_heterogeneity_bias( + dat, + select = "c12hour", + by = c("e42dep", "c172code"), + nested = TRUE + ) + expect_equal(out, "c12hour", ignore_attr = TRUE) +}) diff --git a/tests/testthat/test-model_performance.bayesian.R b/tests/testthat/test-model_performance.bayesian.R index ff78ca3cb..a62f4bf40 100644 --- a/tests/testthat/test-model_performance.bayesian.R +++ b/tests/testthat/test-model_performance.bayesian.R @@ -60,7 +60,7 @@ test_that("model_performance.brmsfit", { expect_equal(perf$R2, 0.954538, tolerance = 1e-3) expect_equal(perf$R2_adjusted, 0.9529004, tolerance = 1e-3) expect_equal(perf$ELPD, -70.40493, tolerance = 1e-3) - expect_identical(colnames(perf), c( + expect_named(perf, c( "ELPD", "ELPD_SE", "LOOIC", "LOOIC_SE", "WAIC", "R2", "R2_marginal", "R2_adjusted", "R2_adjusted_marginal", "ICC", "RMSE", "Sigma" ))