Skip to content

Commit

Permalink
Humble offerings to @IndrajeetPatil (#472)
Browse files Browse the repository at this point in the history
* Create SUPPORT.md

* expect_error with regexp

* expect_warning/error with regexp

* lifecycle badge
  • Loading branch information
mattansb authored Aug 31, 2022
1 parent 58722cc commit 492928a
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 63 deletions.
29 changes: 29 additions & 0 deletions .github/SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Getting help with `{effectsize}`

Thanks for using `{effectsize}`. Before filing an issue, there are a few places
to explore and pieces to put together to make the process as smooth as possible.

Start by making a minimal **repr**oducible **ex**ample using the
[reprex](http://reprex.tidyverse.org/) package. If you haven't heard of or used
reprex before, you're in for a treat! Seriously, reprex will make all of your
R-question-asking endeavors easier (which is a pretty insane ROI for the five to
ten minutes it'll take you to learn what it's all about). For additional reprex
pointers, check out the [Get help!](https://www.tidyverse.org/help/) resource
used by the tidyverse team.

Armed with your reprex, the next step is to figure out where to ask:

* If it's a question: start with StackOverflow. There are more people there to answer questions.
* If it's a bug: you're in the right place, file an issue.
* If you're not sure: let's [discuss](https://github.com/easystats/effectsize/discussions) it and try to figure it out! If your
problem _is_ a bug or a feature request, you can easily return here and
report it.

Before opening a new issue, be sure to [search issues and pull requests](https://github.com/easystats/effectsize/issues) to make sure the
bug hasn't been reported and/or already fixed in the development version. By
default, the search will be pre-populated with `is:issue is:open`. You can
[edit the qualifiers](https://help.github.com/articles/searching-issues-and-pull-requests/)
(e.g. `is:pr`, `is:closed`) as needed. For example, you'd simply
remove `is:open` to search _all_ issues in the repo, open or closed.

Thanks for your help!
1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set.seed(111)
[![downloads](https://cranlogs.r-pkg.org/badges/effectsize)](https://cran.r-project.org/package=effectsize/)
[![total](https://cranlogs.r-pkg.org/badges/grand-total/effectsize)](https://cran.r-project.org/package=effectsize/)
[![status](https://tinyverse.netlify.com/badge/effectsize/)](https://CRAN.R-project.org/package=effectsize/)
[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)


***Significant is just not enough!***
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-convert_statistic.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (require("testthat") && require("effectsize")) {
expect_equal(res3$r, -res1$estimate, tolerance = 0.01, ignore_attr = TRUE)
expect_equal(res3$CI_low, -res1$conf.int[2], tolerance = 0.02, ignore_attr = TRUE)
expect_equal(res3$CI_high, -res1$conf.int[1], tolerance = 0.02, ignore_attr = TRUE)
expect_error(F_to_r(3, 2, 3))
expect_error(F_to_r(3, 2, 3), "df")

res4 <- z_to_r(res1$statistic, res1$parameter)
expect_equal(res4$r, res1$estimate, tolerance = 0.01, ignore_attr = TRUE)
Expand All @@ -60,17 +60,17 @@ if (require("testthat") && require("effectsize")) {
expect_equal(res$d, 0.970, tolerance = 0.01)
expect_equal(res$CI_low, 0.464, tolerance = 0.01)
expect_equal(res$CI_high, 1.469, tolerance = 0.01)
expect_error(F_to_d(16, 2, 68))
expect_error(F_to_d(16, 2, 68), "df")

res <- z_to_d(4, 68)
expect_equal(res$d, 0.970, tolerance = 0.01)
expect_equal(res$CI_low, 0.494, tolerance = 0.01)
expect_equal(res$CI_high, 1.446, tolerance = 0.01)

# depr arg
expect_warning(F_to_d(4^2, 1, 68, pooled = TRUE))
expect_warning(t_to_d(4, 68, pooled = TRUE))
expect_warning(z_to_d(4, 68, pooled = TRUE))
expect_warning(F_to_d(4^2, 1, 68, pooled = TRUE), "deprecated")
expect_warning(t_to_d(4, 68, pooled = TRUE), "deprecated")
expect_warning(z_to_d(4, 68, pooled = TRUE), "deprecated")
})

test_that("eta2", {
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-effectsize.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (require("testthat") && require("effectsize")) {

df <- data.frame(DV = c(x, y), g = rep(1:2, each = 10))
model <- t.test(DV ~ g, data = df, var.equal = TRUE, mu = 3)
expect_warning(effectsize(model))
expect_warning(effectsize(model), "data")

## Auto convert y to factor
Ts <- t.test(mtcars$mpg ~ mtcars$vs)
Expand Down Expand Up @@ -55,13 +55,13 @@ if (require("testthat") && require("effectsize")) {
)

# types
expect_error(effectsize(Xsq1, type = "phi"))
expect_error(effectsize(Xsq1, type = "phi"), "appropriate")
expect_equal(effectsize(Xsq1), cramers_v(contingency_table))
expect_equal(effectsize(Xsq1, type = "w"), w <- cohens_w(contingency_table))
expect_equal(cohens_w(Xsq1), w)

expect_error(effectsize(Xsq1, type = "riskratio"))
expect_error(riskratio(Xsq1))
expect_error(effectsize(Xsq1, type = "riskratio"), "only")
expect_error(riskratio(Xsq1), "only")

contingency_table22 <- contingency_table[1:2, 1:2]
Xsq4 <- chisq.test(contingency_table22)
Expand All @@ -85,21 +85,21 @@ if (require("testthat") && require("effectsize")) {
expected.dfc <<- c(0.165, 0.835)

x <- chisq.test(x = observed.dfc, p = expected.dfc)
expect_error(effectsize(x, type = "v"))
expect_error(effectsize(x, type = "phi"))
expect_error(effectsize(x, type = "v"), "goodness")
expect_error(effectsize(x, type = "phi"), "appropriate")
expect_equal(effectsize(x), effectsize(x, type = "chi"))
expect_equal(effectsize(x, type = "chi"), nchi <- normalized_chi(observed.dfc, p = expected.dfc))
expect_equal(normalized_chi(x), nchi)
})

test_that("cor.test / other", {
r_ <- cor.test(iris$Sepal.Width, iris$Sepal.Length)
expect_warning(effectsize(r_))
expect_warning(effectsize(r_), "parameters")
})

test_that("one way", {
onew <- oneway.test(mpg ~ cyl, mtcars)
expect_warning(effectsize(onew))
expect_warning(effectsize(onew), "var")


onew <- oneway.test(mpg ~ cyl, mtcars, var.equal = TRUE)
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-eta_squared.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ if (require("testthat") && require("effectsize")) {
F_to_eta2(mod1[["F value"]], mod1$Df, mod1$DenDF),
ignore_attr = TRUE
)
expect_warning(eta_squared(mod1, partial = FALSE))
expect_warning(eta_squared(mod1, generalized = TRUE))
expect_warning(eta_squared(mod1, partial = FALSE), "partial")
expect_warning(eta_squared(mod1, generalized = TRUE), "generalized")

mod2 <- mod1
mod2$`F value` <- NULL
expect_error(eta_squared(mod2))
expect_error(eta_squared(mod2), "does not")
})

# aov ---------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (require("testthat") && require("effectsize")) {
})

test_that("validate data from formula", {
expect_error(cohens_d(mpg ~ cyl, data = mtcars))
expect_error(cohens_d(mpg ~ cyl, data = mtcars), "exactly")
expect_error(cohens_d(mpg ~ cyl, data = mtcars, subset = cyl %in% c(4, 6)), regexp = NA)

d1 <- cohens_d(mpg ~ cyl,
Expand Down Expand Up @@ -41,13 +41,13 @@ if (require("testthat") && require("effectsize")) {
expect_equal(d1, d3)
expect_equal(d1, d4)

expect_error(rank_biserial(mpg ~ cyl, data = mtcars))
expect_error(rank_biserial(mpg ~ cyl, data = mtcars), "exactly")
expect_error(rank_biserial(mpg ~ cyl, data = mtcars, subset = cyl %in% c(4, 6)), regexp = NA)

expect_error(sd_pooled(mpg ~ cyl, data = mtcars))
expect_error(sd_pooled(mpg ~ cyl, data = mtcars), "exactly")
expect_error(sd_pooled(mpg ~ cyl, data = mtcars, subset = cyl %in% c(4, 6)), regexp = NA)

expect_error(cles(mpg ~ cyl, data = mtcars))
expect_error(cles(mpg ~ cyl, data = mtcars), "exactly")
expect_error(cles(mpg ~ cyl, data = mtcars, subset = cyl %in% c(4, 6)), regexp = NA)

d <- expand.grid(id = 1:30, g = 1:4)
Expand Down
58 changes: 29 additions & 29 deletions tests/testthat/test-interpret.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ if (require("testthat") && require("effectsize")) {
interpret(c(0.01, 0.005, 0.08), rules_grid)[1:3],
c("very significant", "very significant", "not significant")
)
expect_error(interpret_r(0.6, rules(c(0.5), c("A", "B", "C"))))
expect_error(interpret_r(0.6, rules(c(0.5, 0.2, 0.7), c("A", "B", "C", "D"))))
expect_error(rules(c(0.5), c("A", "B", "C")), "Too many")
expect_error(rules(c(0.5, 0.2, 0.7), c("A", "B", "C", "D")), "sorted")


r1 <- rules(c(0, 1), labels = c("some", "few", "many"))
Expand All @@ -28,7 +28,7 @@ if (require("testthat") && require("effectsize")) {
expect_equal(interpret_r(0.7, "evans1996")[1], "strong")
expect_equal(interpret_r(c(0.5, -0.08), "cohen1988")[1:2], c("large", "very small"))
expect_equal(interpret_r(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_r(0.6, "DUPA"))
expect_error(interpret_r(0.6, "DUPA"), "must be")
})


Expand All @@ -38,7 +38,7 @@ if (require("testthat") && require("effectsize")) {
expect_equal(interpret_p(0.08)[1], "not significant")
expect_equal(interpret_p(c(0.01, 0.08))[1:2], c("significant", "not significant"))
expect_equal(interpret_p(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_p(0.6, "DUPA"))
expect_error(interpret_p(0.6, "DUPA"), "must be")
})


Expand All @@ -53,14 +53,14 @@ if (require("testthat") && require("effectsize")) {
expect_equal(interpret_cohens_d(c(0.45, 0.85), "cohen1988")[1:2], c("small", "large"))
expect_equal(interpret_cohens_d(c(0.45, 0.85), "lovakov2021")[1:2], c("medium", "large"))
expect_equal(interpret_cohens_d(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_cohens_d(0.6, "DUPA"))
expect_error(interpret_cohens_d(0.6, "DUPA"), "must be")
})

test_that("interpret_cohens_g", {
expect_equal(interpret_cohens_g(0.021)[1], "very small")
expect_equal(interpret_cohens_g(c(0.10, 0.35), "cohen1988")[1:2], c("small", "large"))
expect_equal(interpret_cohens_g(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_cohens_g(0.6, "DUPA"))
expect_error(interpret_cohens_g(0.6, "DUPA"), "must be")
})


Expand All @@ -69,7 +69,7 @@ if (require("testthat") && require("effectsize")) {
expect_equal(interpret_rope(c(0.50, 1), ci = 0.9)[1:2], c("undecided", "negligible"))
expect_equal(interpret_rope(c(0.98, 0.991), ci = 1)[1:2], c("probably negligible", "negligible"))
expect_equal(interpret_rope(0.6, , rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_rope(0.6, , "DUPA"))
expect_error(interpret_rope(0.6, , "DUPA"), "must be")
})


Expand All @@ -78,7 +78,7 @@ if (require("testthat") && require("effectsize")) {
expect_equal(interpret_oddsratio(c(1, 3))[1:2], c("very small", "small"))
expect_equal(interpret_oddsratio(c(1, 3), "cohen1988")[1:2], c("very small", "medium"))
expect_equal(interpret_oddsratio(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_oddsratio(0.6, "DUPA"))
expect_error(interpret_oddsratio(0.6, "DUPA"), "must be")
})


Expand All @@ -88,12 +88,12 @@ if (require("testthat") && require("effectsize")) {
expect_equal(interpret_r2(c(0.1, 0.4), "chin1998")[1:2], c("very weak", "moderate"))
expect_equal(interpret_r2(c(0.1, 0.4), "hair2011")[1:2], c("very weak", "weak"))
expect_equal(interpret_r2(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_r2(0.6, "DUPA"))
expect_error(interpret_r2(0.6, "DUPA"), "must be")
})


test_that("interpret_bf", {
expect_warning(interpret_bf(-2))
expect_warning(interpret_bf(-2), "Negative")
expect_equal(interpret_bf(1)[1], "no evidence against or in favour of")
expect_equal(
interpret_bf(c(0.8, 3.5), "jeffreys1961")[1:2],
Expand All @@ -104,7 +104,7 @@ if (require("testthat") && require("effectsize")) {
c("weak evidence against", "positive evidence in favour of")
)
expect_equal(interpret_bf(2, rules(c(0.5), c("A", "B")))[1], "B evidence in favour of")
expect_error(interpret_bf(2, "DUPA"))
expect_error(interpret_bf(2, "DUPA"), "must be")

skip_on_cran() # just in case there are changes in insight
bf <- c(10^seq(-4, 4), NA)
Expand All @@ -126,7 +126,7 @@ if (require("testthat") && require("effectsize")) {
expect_equal(interpret_omega_squared(0.1)[1], "medium")
expect_equal(interpret_omega_squared(c(0.1, 0.25))[1:2], c("medium", "large"))
expect_equal(interpret_omega_squared(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_omega_squared(0.6, "DUPA"))
expect_error(interpret_omega_squared(0.6, "DUPA"), "must be")

# these should be same
expect_equal(interpret_eta_squared(0.1)[1], interpret_omega_squared(0.1)[1])
Expand All @@ -144,7 +144,7 @@ if (require("testthat") && require("effectsize")) {
)
expect_equal(interpret_kendalls_w(0.9)[1], "almost perfect agreement")
expect_equal(interpret_kendalls_w(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_kendalls_w(0.6, "DUPA"))
expect_error(interpret_kendalls_w(0.6, "DUPA"), "must be")
})


Expand All @@ -153,15 +153,15 @@ if (require("testthat") && require("effectsize")) {
expect_equal(interpret_rhat(c(1, 1.02))[1:2], c("converged", "failed"))
expect_equal(interpret_rhat(c(1, 1.02), "gelman1992")[1:2], c("converged", "converged"))
expect_equal(interpret_rhat(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_rhat(0.6, "DUPA"))
expect_error(interpret_rhat(0.6, "DUPA"), "must be")
})


test_that("interpret_ess", {
expect_equal(interpret_ess(1000)[1], "sufficient")
expect_equal(interpret_ess(c(1000, 800))[1:2], c("sufficient", "insufficient"))
expect_equal(interpret_ess(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_ess(0.6, "DUPA"))
expect_error(interpret_ess(0.6, "DUPA"), "must be")
})


Expand Down Expand Up @@ -189,16 +189,16 @@ if (require("testthat") && require("effectsize")) {
expect_equal(interpret_rmsea(0.6, cr), "B", ignore_attr = TRUE)
expect_equal(interpret_srmr(0.6, cr), "B", ignore_attr = TRUE)

expect_error(interpret_gfi(0.6, "DUPA"))
expect_error(interpret_agfi(0.6, "DUPA"))
expect_error(interpret_nfi(0.6, "DUPA"))
expect_error(interpret_nnfi(0.6, "DUPA"))
expect_error(interpret_cfi(0.6, "DUPA"))
expect_error(interpret_rfi(0.6, "DUPA"))
expect_error(interpret_ifi(0.6, "DUPA"))
expect_error(interpret_pnfi(0.6, "DUPA"))
expect_error(interpret_rmsea(0.6, "DUPA"))
expect_error(interpret_srmr(0.6, "DUPA"))
expect_error(interpret_gfi(0.6, "DUPA"), "must be")
expect_error(interpret_agfi(0.6, "DUPA"), "must be")
expect_error(interpret_nfi(0.6, "DUPA"), "must be")
expect_error(interpret_nnfi(0.6, "DUPA"), "must be")
expect_error(interpret_cfi(0.6, "DUPA"), "must be")
expect_error(interpret_rfi(0.6, "DUPA"), "must be")
expect_error(interpret_ifi(0.6, "DUPA"), "must be")
expect_error(interpret_pnfi(0.6, "DUPA"), "must be")
expect_error(interpret_rmsea(0.6, "DUPA"), "must be")
expect_error(interpret_srmr(0.6, "DUPA"), "must be")

skip_on_cran()
skip_if_not_installed("lavaan")
Expand All @@ -219,20 +219,20 @@ if (require("testthat") && require("effectsize")) {
test_that("interpret_icc", {
expect_equal(interpret_icc(c(0.45, 0.55, 0.8, 0.95)), c("poor", "moderate", "good", "excellent"), ignore_attr = TRUE)
expect_equal(interpret_icc(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_icc(0.6, "DUPA"))
expect_error(interpret_icc(0.6, "DUPA"), "must be")
})

test_that("interpret_vif", {
expect_equal(interpret_vif(c(1, 5.5, 10)), c("low", "moderate", "high"), ignore_attr = TRUE)
expect_equal(interpret_icc(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_icc(0.6, "DUPA"))
expect_error(interpret_icc(0.6, "DUPA"), "must be")
})

test_that("interpret_pd", {
expect_equal(interpret_pd(c(0.9, 0.99)), c("not significant", "significant"), ignore_attr = TRUE)
expect_equal(interpret_pd(c(0.9, 0.99), "makowski2019"), c("uncertain", "likely existing"), ignore_attr = TRUE)
expect_equal(interpret_pd(0.6, rules(c(0.5), c("A", "B")))[1], "B")
expect_error(interpret_pd(0.6, "DUPA"))
expect_error(interpret_pd(0.6, "DUPA"), "must be")
})

# interpret effectsize_table ----
Expand All @@ -252,6 +252,6 @@ if (require("testthat") && require("effectsize")) {
expect_output(print(V_), "large")
expect_output(print(V_), "Interpretation rule: funder2019")

expect_error(interpret(d))
expect_error(interpret(d), "MUST specify")
})
}
20 changes: 10 additions & 10 deletions tests/testthat/test-standardized_differences.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ if (require("testthat") && require("effectsize")) {
expect_error(cohens_d(df$a ~ df$c), regexp = NA)
expect_equal(cohens_d("exp_a", "c", data = df), cohens_d(exp(a) ~ c, data = df))

expect_error(cohens_d(a ~ b, data = df))
expect_error(cohens_d(a ~ d, data = df))
expect_error(cohens_d("a", "d", data = df))
expect_error(cohens_d("c", "c", data = df))
expect_error(cohens_d(a2, df$c))
expect_error(cohens_d("a", "aa", data = df))

expect_warning(cohens_d("b", "e", data = df))
expect_error(cohens_d(a ~ b, data = df), "exactly")
expect_error(cohens_d(a ~ d, data = df), "exactly")
expect_error(cohens_d("a", "d", data = df), "exactly")
expect_error(cohens_d("c", "c", data = df), "non-numeric")
expect_error(cohens_d(a2, df$c), "length")
expect_error(cohens_d("a", "aa", data = df), "missing")

expect_warning(cohens_d("b", "e", data = df), "convert")
})

test_that("cohens d - grouping character vector", {
Expand Down Expand Up @@ -107,8 +107,8 @@ if (require("testthat") && require("effectsize")) {

test_that("glass_delta", {
# must be 2 samples
expect_error(glass_delta(1:10))
expect_error(glass_delta(wt, data = mtcars))
expect_error(glass_delta(1:10), "two")
expect_error(glass_delta("wt", data = mtcars), "two")

x <- glass_delta(wt ~ am, data = mtcars)
expect_equal(colnames(x)[1], "Glass_delta")
Expand Down
Loading

0 comments on commit 492928a

Please sign in to comment.