Skip to content
Open
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export(median_diff)
importFrom(ggplot2,.pt)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
importFrom(dplyr, n)
11 changes: 9 additions & 2 deletions R/001_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,19 @@ load <- function(

## Check to ensure control & treatment groups have the same sample size if is_paired is TRUE
if (is_paired) {
if (length(unique(Ns$n)) > 1) {
cli::cli_abort(c("{.field data} is paired, as indicated by {.field paired} but size of control and treatment groups are not equal.",
for(i in idx) {
unlisted_pair <- unlist(i)
filter_df <- data %>%
dplyr::filter(!!enquo_x %in% unlisted_pair)
check_ns <- filter_df %>%
dplyr::count(!!enquo_x)
if (length(unique(check_ns$n)) > 1) {
cli::cli_abort(c("{.field data} is paired, as indicated by {.field paired} but size of control and treatment groups are not equal.",
"x" = "Ensure that the size of control and treatment groups are the same for paired comparisons."
))
}
}
}

# Extending ylim for plotting
ylim[1] <- ylim[1] - (ylim[2] - ylim[1]) / 25
Expand Down
33 changes: 19 additions & 14 deletions tests/testthat/test_001_api.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
describe("Given non-valid params", {
# since this is more of an integration test, this unit test logic is repeated in test_001_utils.R
np_dataset <- generate_non_proportional_dataset()
p_dataset <- generate_proportional_dataset()

# for paired data test
np_dataset_trunc <- np_dataset[-2, ]

test_that("it should detect invalid x value", {
expect_error(
dabestr::load(np_dataset,
x = Grou, y = Measurement,
idx = c("Control 1", "Test 1")
),
regexp = "Column x is not in data"
)
})

describe("Testing load function", {
describe("Given valid params", {
describe("Given non proportional dataset", {
Expand Down Expand Up @@ -36,20 +54,7 @@ describe("Testing load function", {
})
})

describe("Given non-valid params", {
# since this is more of an integration test, this unit test logic is repeated in test_001_utils.R
np_dataset <- generate_non_proportional_dataset()
p_dataset <- generate_proportional_dataset()

test_that("it should detect invalid x value", {
expect_error(
dabestr::load(np_dataset,
x = Grou, y = Measurement,
idx = c("Control 1", "Test 1")
),
regexp = "Column x is not in data"
)
})

test_that("it should detect invalid y value", {
expect_error(
Expand Down Expand Up @@ -147,7 +152,7 @@ describe("Testing load function", {

test_that("it should detect invalid dataset size", {
expect_error(
dabestr::load(np_dataset[-2, ],
dabestr::load(np_dataset_trunc,
x = Group, y = Measurement,
idx = c("Control 1", "Test 1", "Test 2"), paired = "sequential",
id_col = ID
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test_001_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ describe("Testing validate_load_params function", {
np_dataset <- generate_non_proportional_dataset()
p_dataset <- generate_proportional_dataset()

# for paired data test
np_dataset_trunc <- np_dataset[-2, ]

test_that("it should detect invalid x value", {
expect_error(
dabestr::load(np_dataset,
Expand Down Expand Up @@ -109,7 +112,7 @@ describe("Testing validate_load_params function", {

test_that("it should detect invalid dataset size", {
expect_error(
dabestr::load(np_dataset[-2, ],
dabestr::load(np_dataset_trunc,
x = Group, y = Measurement,
idx = c("Control 1", "Test 1", "Test 2"), paired = "sequential",
id_col = ID
Expand Down
2 changes: 2 additions & 0 deletions vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.html
*.R

/.quarto/
1 change: 1 addition & 0 deletions vignettes/plot_aesthetics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
library(dplyr)
```

Controlling plot aesthetics is straightforward in `dabestr`. A key feature of `dabestr` is the ability for users to freely customize various components of a `dabestr` estimation plot, allowing for the creation of an optimal-looking plot.
Expand Down
1 change: 1 addition & 0 deletions vignettes/tutorial_basics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The dataset is first processed into the dabestr format using the `load()` functi

```{r setup, warning = FALSE, message = FALSE}
library(dabestr)
library(dplyr)
```

## Create dataset for demo
Expand Down
1 change: 1 addition & 0 deletions vignettes/tutorial_deltadelta.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ knitr::opts_chunk$set(

```{r, include = FALSE, warning = FALSE, message = FALSE}
library(dabestr)
library(dplyr)
```

This vignette documents how `dabestr` is able to compute the calculation of delta-delta, an experimental function that allows the comparison between two bootstrapped effect sizes computed from two independent categorical variables.
Expand Down
1 change: 1 addition & 0 deletions vignettes/tutorial_minimeta.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ For more information on meta-analysis, please refer to [Chapter 10](https://trai

```{r setup, warning = FALSE, message = FALSE}
library(dabestr)
library(dplyr)
```

## Create dataset for demo
Expand Down
1 change: 1 addition & 0 deletions vignettes/tutorial_proportion_plots.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This vignette documents how the `dabestr` package is able to generate proportion

```{r setup, warning = FALSE, message = FALSE}
library(dabestr)
library(dplyr)
```

## Create dataset for demo
Expand Down
50 changes: 50 additions & 0 deletions vignettes/tutorial_repeated_measures.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ To use these features, simply declare the `paired` argument as either "sequentia

```{r setup, warning = FALSE, message = FALSE}
library(dabestr)
library(dplyr)
```

## Create dataset for demo
Expand Down Expand Up @@ -221,3 +222,52 @@ dabest_plot(multi_baseline_repeated_measures.mean_diff,
raw_marker_size = 0.5, raw_marker_alpha = 0.3
)
```

## Paired groups with different sample sizes across comparisons

Repeated-measures plots also work when different comparison pairs have different sample sizes, as long as each pair is internally balanced.

```{r}
set.seed(12345)
N1 <- 20
N2 <- 10

df_unequal_pairs <- tibble::tibble(
Group = rep(c("Control 1", "Test 1", "Control 2", "Test 2"), c(N1, N1, N2, N2)),
Measurement = c(
rnorm(N1, mean = 3, sd = 0.4), # Control 1
rnorm(N1, mean = 3.5, sd = 0.5), # Test 1
rnorm(N2, mean = 2.5, sd = 0.4), # Control 2
rnorm(N2, mean = 3.0, sd = 0.5) # Test 2
),
ID = c(1:N1, 1:N1, 1:N2, 1:N2)
)
```

```{r, warning = FALSE}
# Each pair is internally balanced even though the two pairs differ in size.
multi_unequal_pairs.mean_diff <- load(df_unequal_pairs,
x = Group, y = Measurement,
idx = list(c("Control 1", "Test 1"), c("Control 2", "Test 2")),
paired = "sequential", id_col = ID
) %>%
mean_diff()

dabest_plot(multi_unequal_pairs.mean_diff,
raw_marker_size = 0.5, raw_marker_alpha = 0.3
)
```

An unbalanced pair (different n *within* a pair) is still caught as an error:

```{r, error = TRUE}
# Remove one row from Test 1 so Control 1 (n=20) and Test 1 (n=19) are mismatched within the pair.
df_bad_pair <- df_unequal_pairs %>%
dplyr::filter(!(Group == "Test 1" & ID == 1))

load(df_bad_pair,
x = Group, y = Measurement,
idx = list(c("Control 1", "Test 1"), c("Control 2", "Test 2")),
paired = "sequential", id_col = ID
)
```
Loading