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

support for quantile regression and mixed effects quantile regression #685

Merged
merged 5 commits into from
Feb 16, 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
3 changes: 2 additions & 1 deletion 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.10.8.14
Version: 0.10.8.15
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -128,6 +128,7 @@ Suggests:
patchwork,
pscl,
psych,
quantreg,
qqplotr (>= 0.0.6),
randomForest,
rempsyc,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ S3method(check_outliers,metagen)
S3method(check_outliers,numeric)
S3method(check_outliers,rma)
S3method(check_outliers,rma.uni)
S3method(check_outliers,rq)
S3method(check_outliers,rqs)
S3method(check_outliers,rqss)
S3method(check_overdispersion,default)
S3method(check_overdispersion,fixest)
S3method(check_overdispersion,fixest_multi)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
* Fixed edge cases in `check_collinearity()` and `check_outliers()` for models
with response variables of classes `Date`, `POSIXct`, `POSIXlt` or `difftime`.

* Fixed issue with `check_model()` for models of package *quantreg*.

# performance 0.10.8

## Changes
Expand Down
9 changes: 9 additions & 0 deletions R/check_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
#' group_iris <- datawizard::data_group(iris, "Species")
#' check_outliers(group_iris)
#'
#' @examplesIf require("see") && require("bigutilsr") && require("loo") && require("MASS") && require("ICSOutlier") && require("ICS") && require("dbscan")

Check warning on line 313 in R/check_outliers.R

View workflow job for this annotation

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

file=R/check_outliers.R,line=313,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 154 characters.
#' \donttest{
#' # You can also run all the methods
#' check_outliers(data, method = "all", verbose = FALSE)
Expand Down Expand Up @@ -1192,7 +1192,7 @@

# Isolation Forest
# if ("iforest" %in% method) {
# out <- c(out, .check_outliers_iforest(x, threshold = thresholds$iforest))

Check warning on line 1195 in R/check_outliers.R

View workflow job for this annotation

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

file=R/check_outliers.R,line=1195,col=7,[commented_code_linter] Remove commented code.
# }

# Local Outlier Factor
Expand Down Expand Up @@ -1576,7 +1576,7 @@
out <- cbind(out, ID.names)
}

# out$Distance_IQR <- Distance_IQR

Check warning on line 1579 in R/check_outliers.R

View workflow job for this annotation

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

file=R/check_outliers.R,line=1579,col=5,[commented_code_linter] Remove commented code.

out$Distance_IQR <- vapply(as.data.frame(t(Distance_IQR)), function(x) {
ifelse(all(is.na(x)), NA_real_, max(x, na.rm = TRUE))
Expand Down Expand Up @@ -1758,7 +1758,7 @@
}

# check whether N to p ratio is not too large, else MCD flags too many outliers
# See #672: This does seem to be a function of the N/p (N = sample size; p =

Check warning on line 1761 in R/check_outliers.R

View workflow job for this annotation

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

file=R/check_outliers.R,line=1761,col=5,[commented_code_linter] Remove commented code.
# number of parameters) ratio. When it is larger than 10, the % of outliers
# flagged is okay (in well behaved data). This makes sense: the MCD looks at
# the cov matrix of subsamples of the data - with high dimensional data, small
Expand Down Expand Up @@ -1899,21 +1899,21 @@


# .check_outliers_iforest <- function(x, threshold = 0.025) {
# out <- data.frame(Row = seq_len(nrow(x)))

Check warning on line 1902 in R/check_outliers.R

View workflow job for this annotation

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

file=R/check_outliers.R,line=1902,col=5,[commented_code_linter] Remove commented code.
#
# # Install packages
# insight::check_if_installed("solitude")

Check warning on line 1905 in R/check_outliers.R

View workflow job for this annotation

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

file=R/check_outliers.R,line=1905,col=4,[commented_code_linter] Remove commented code.
#
# # Compute
# if (utils::packageVersion("solitude") < "0.2.0") {
# iforest <- solitude::isolationForest(x)

Check warning on line 1909 in R/check_outliers.R

View workflow job for this annotation

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

file=R/check_outliers.R,line=1909,col=7,[commented_code_linter] Remove commented code.
# out$Distance_iforest <- stats::predict(iforest, x, type = "anomaly_score")

Check warning on line 1910 in R/check_outliers.R

View workflow job for this annotation

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

file=R/check_outliers.R,line=1910,col=7,[commented_code_linter] Remove commented code.
# } else if (utils::packageVersion("solitude") == "0.2.0") {
# stop(paste("Must update package `solitude` (above version 0.2.0).",
# "Please run `install.packages('solitude')`."), call. = FALSE)
# } else {
# iforest <- solitude::isolationForest$new(sample_size = nrow(x))

Check warning on line 1915 in R/check_outliers.R

View workflow job for this annotation

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

file=R/check_outliers.R,line=1915,col=7,[commented_code_linter] Remove commented code.
# suppressMessages(iforest$fit(x))

Check warning on line 1916 in R/check_outliers.R

View workflow job for this annotation

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

file=R/check_outliers.R,line=1916,col=7,[commented_code_linter] Remove commented code.
# out$Distance_iforest <- iforest$scores$anomaly_score
# }
#
Expand Down Expand Up @@ -1987,3 +1987,12 @@

#' @export
check_outliers.glmrob <- check_outliers.glmmTMB

#' @export
check_outliers.rq <- check_outliers.glmmTMB

#' @export
check_outliers.rqs <- check_outliers.glmmTMB

#' @export
check_outliers.rqss <- check_outliers.glmmTMB
8 changes: 1 addition & 7 deletions R/model_performance.bayesian.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#'
#' - **PCP**: percentage of correct predictions, see [performance_pcp()].
#'
#' @examplesIf require("rstanarm") && require("rstantools") && require("BayesFactor")
#' @examplesIf require("rstanarm") && require("rstantools")
#' \donttest{
#' model <- suppressWarnings(rstanarm::stan_glm(
#' mpg ~ wt + cyl,
Expand All @@ -59,12 +59,6 @@
#' refresh = 0
#' ))
#' model_performance(model)
#'
#' model <- BayesFactor::generalTestBF(carb ~ am + mpg, mtcars)
#'
#' model_performance(model)
#' model_performance(model[3])
#' model_performance(model, average = TRUE)
#' }
#' @seealso [r2_bayes]
#' @references Gelman, A., Goodrich, B., Gabry, J., and Vehtari, A. (2018).
Expand Down
20 changes: 1 addition & 19 deletions R/r2_bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#' `r2_posterior()` is the actual workhorse for `r2_bayes()` and
#' returns a posterior sample of Bayesian R2 values.
#'
#' @examplesIf require("rstanarm") && require("rstantools") && require("BayesFactor") && require("brms")
#' @examplesIf require("rstanarm") && require("rstantools") && require("brms")
#' library(performance)
#' \donttest{
#' model <- suppressWarnings(rstanarm::stan_glm(
Expand All @@ -53,24 +53,6 @@
#' r2_bayes(model)
#' }
#'
#' BFM <- BayesFactor::generalTestBF(mpg ~ qsec + gear, data = mtcars, progress = FALSE)
#' FM <- BayesFactor::lmBF(mpg ~ qsec + gear, data = mtcars)
#'
#' r2_bayes(FM)
#' r2_bayes(BFM[3])
#' r2_bayes(BFM, average = TRUE) # across all models
#'
#' # with random effects:
#' mtcars$gear <- factor(mtcars$gear)
#' model <- BayesFactor::lmBF(
#' mpg ~ hp + cyl + gear + gear:wt,
#' mtcars,
#' progress = FALSE,
#' whichRandom = c("gear", "gear:wt")
#' )
#'
#' r2_bayes(model)
#'
#' \donttest{
#' model <- suppressWarnings(brms::brm(
#' mpg ~ wt + cyl,
Expand Down
8 changes: 1 addition & 7 deletions man/model_performance.stanreg.Rd

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

20 changes: 1 addition & 19 deletions man/r2_bayes.Rd

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

8 changes: 8 additions & 0 deletions tests/testthat/test-check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ test_that("`check_model()` for invalid models", {
m1 <- lm(y ~ 1, data = dd)
expect_error(check_model(m1))
})

test_that("`check_model()` works for quantreg", {
skip_if_not_installed("quantreg")
data(engel, package = "quantreg")
qm <- quantreg::rq(foodexp ~ income, data = engel)
x <- check_model(qm, verbose = FALSE)
expect_s3_class(x, "check_model")
})
26 changes: 1 addition & 25 deletions vignettes/r2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ knitr::opts_chunk$set(
)
options(digits = 2)

pkgs <- c(
"effectsize", "BayesFactor", "lme4", "rstanarm"
)
pkgs <- c("effectsize", "lme4", "rstanarm")
successfully_loaded <- sapply(pkgs, requireNamespace, quietly = TRUE)
if (all(successfully_loaded)) {
library(performance)
library(effectsize)
library(BayesFactor)
library(lme4)
library(rstanarm)
}
Expand Down Expand Up @@ -147,27 +144,6 @@ model <- stan_lmer(Petal.Length ~ Petal.Width + (1 | Species), data = iris, refr
r2(model)
```

Let's look at another regression analysis carried out with `{BayesFactor}` package.

```{r, eval=successfully_loaded["BayesFactor"] && utils::packageVersion("BayesFactor") >= package_version("0.9.12-4.3")}
library(BayesFactor)
data(puzzles)

m1 <- anovaBF(extra ~ group + ID,
data = sleep,
whichRandom = "ID", progress = FALSE
)

r2(m1)

m2 <- generalTestBF(RT ~ shape * color + ID,
data = puzzles, whichRandom = "ID",
neverExclude = "ID", progress = FALSE
)

r2(m2)
```

# Comparing change in R2 using Cohen's *f*

Cohen's $f$ (of [ANOVA fame](https://easystats.github.io/effectsize/articles/anovaES.html)) can be used as a measure of effect size in the context of sequential multiple regression (i.e., [**nested models**](https://easystats.github.io/performance/reference/test_performance.html)).
Expand Down
Loading