Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare CRAN submission #767

Merged
merged 10 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -160,4 +160,3 @@ Config/Needs/website:
r-lib/pkgdown,
easystats/easystatstemplate
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/see, easystats/insight
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/check_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check warning on line 106 in R/check_dag.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/check_dag.R,line=106,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 154 characters.

Check warning on line 106 in R/check_dag.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_dag.R,line=106,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 154 characters.
#' # no adjustment needed
#' check_dag(
#' y ~ x + b,
Expand Down
3 changes: 2 additions & 1 deletion R/check_singularity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
Expand Down
20 changes: 16 additions & 4 deletions R/model_performance.lm.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand Down Expand Up @@ -39,7 +39,7 @@
#' model <- glm(vs ~ wt + mpg, data = mtcars, family = "binomial")
#' model_performance(model)
#' @export
model_performance.lm <- function(model, metrics = "all", verbose = TRUE, ...) {

Check warning on line 42 in R/model_performance.lm.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/model_performance.lm.R,line=42,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 54 to at most 40.
if (any(tolower(metrics) == "log_loss")) {
metrics[tolower(metrics) == "log_loss"] <- "LOGLOSS"
}
Expand Down Expand Up @@ -209,6 +209,18 @@
#' @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

Expand Down
1 change: 0 additions & 1 deletion R/r2.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions R/r2_coxsnell.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand All @@ -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, ...) {
Expand Down
4 changes: 2 additions & 2 deletions R/r2_mlm.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This is a patch release that fixes failing CRAN checks for Mac OS old-rel.
Maintance release.
2 changes: 1 addition & 1 deletion man/check_dag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/check_singularity.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/model_performance.lm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions man/r2_coxsnell.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/testthat/test-check_heterogeneity_bias.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-model_performance.bayesian.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))
Expand Down
Loading