`difference` is not strictly less than 60. Difference: 20.6

testthat::test_that("rmm function validates inputs correctly", {
testthat::expect_error(rmm(data = NULL, Ps_col = Ps, outcome_col = survival))
df <- tibble::tibble(Ps = plogis(rnorm(1000, mean = 2, sd = 1.5)), survival = rbinom(1000, 1, prob = 0.9))
testthat::expect_error(rmm(data = df, outcome_col = survival, n_samples = 5))
testthat::expect_error(rmm(data = df, Ps_col = Ps))
df_non_binary <- tibble::tibble(Ps = plogis(rnorm(5, mean = 2, sd = 1.5)), survival = c(1, 2, 3, 4, 5))
testthat::expect_error(rmm(data = df_non_binary, Ps_col = Ps, outcome_col = survival, n_samples = 5))
df_non_numeric <- tibble::tibble(Ps = c("a", "b", "c"), survival = c(1, 0, 1))
testthat::expect_error(rmm(data = df_non_numeric, Ps_col = Ps, outcome_col = survival, n_samples = 5))
df_ps_above_1 <- tibble::tibble(Ps = sample(30:150, size = 1000, replace = TRUE), survival = sample(c(1,0), size = 1000, replace = TRUE))
testthat::expect_error(rmm(data = df_ps_above_1, Ps_col = Ps, outcome_col = survival, n_samples = 5))
testthat::expect_error(rmm(data = data.frame(Ps = c(0.1, 0.5, 0.9, .005), survival = c(1, 0, 1, 0)),
testthat::test_that("rmm function computes binning correctly", {
# Test the binning process with some mock data
result <- rmm(data = df, Ps_col = Ps, outcome_col = survival, Divisor1 = 5, Divisor2 = 5, n_samples = 5)
testthat::expect_true(all(c("population_RMM_LL", "population_RMM", "population_RMM_UL", "population_CI", "bootstrap_RMM_LL", "bootstrap_RMM", "bootstrap_RMM_UL", "bootstrap_CI") %in% colnames(result)))
testthat::test_that("rmm function calculates RMM and its confidence intervals", {
# Test with mock data for RMM calculation
# Test for upper and lower bounds of RMM
testthat::test_that("rmm function handles the pivot argument correctly", {
result_pivot <- rmm(data = df, Ps_col = Ps, outcome_col = survival, pivot = TRUE, n_samples = 5)
result_no_pivot <- rmm(data = df, Ps_col = Ps, outcome_col = survival, pivot = FALSE, n_samples = 5)
testthat::test_that("rmm function handles edge cases correctly", {
df_one_row <- tibble::tibble(Ps = 0.50, survival = 1)
testthat::expect_error(rmm(data = df_one_row, Ps_col = Ps, outcome_col = survival))
df_na_ps <- tibble::tibble(Ps = c(NA, NA, NA), survival = c(1, 0, 1))
testthat::expect_error(rmm(data = df_na_ps, Ps_col = Ps, outcome_col = survival))
df_na_outcome <- tibble::tibble(Ps = c(.20, .50, .80), survival = c(NA, NA, NA))
testthat::expect_error(rmm(data = df_na_outcome, Ps_col = Ps, outcome_col = survival))
testthat::test_that("rmm function handles the seed argument correctly", {
# Test with a fixed seed value to ensure reproducibility
result_1 <- rmm(data = df, Ps_col = Ps, outcome_col = survival, n_samples = 5, seed = 123)
result_2 <- rmm(data = df, Ps_col = Ps, outcome_col = survival, n_samples = 5, seed = 123)
# Ensure the results are identical with the same seed
# Test with a different seed to check if results change
result_3 <- rmm(data = df, Ps_col = Ps, outcome_col = survival, n_samples = 5, seed = 456)
testthat::test_that("rmm function handles the group_vars argument correctly", {
# Test with grouping by a variable (e.g., a factor)
df <- tibble::tibble(Ps = plogis(rnorm(1000, mean = 2, sd = 1.5)),
result_grouped <- rmm(data = df, Ps_col = Ps, outcome_col = survival, group_vars = "group", n_samples = 100)
# Test if the output contains the group variable
# Ensure that results are calculated per group
group_means <- result_grouped %>% dplyr::group_by(group) %>% dplyr::summarize(mean_rmm = mean(population_RMM, na.rm = TRUE))
testthat::test_that("rmm function handles edge cases with seed and group_vars", {
df_missing_group <- tibble::tibble(Ps = plogis(rnorm(1000, mean = 2, sd = 1.5)), survival = rbinom(1000, 1, prob = 0.9))
result_no_group <- rmm(data = df_missing_group, Ps_col = Ps, outcome_col = survival, n_samples = 5, seed = 123)
# Test that no error occurs and RMM is calculated
# Test with group_vars but no valid grouping
df_invalid_group <- tibble::tibble(Ps = plogis(rnorm(1000, mean = 2, sd = 1.5)),
testthat::expect_error(rmm(data = df_invalid_group, Ps_col = Ps, outcome_col = survival, group_vars = group, n_samples = 5, seed = 123))
testthat::test_that("rmm function handles missing values with seed and group_vars correctly", {
# Create a larger dataset with missing values in Ps, survival, and group variables
Ps = c(rep(NA, 200), plogis(rnorm(800, mean = 2, sd = 1.5))),  # 200 NAs in Ps
survival = c(rep(NA, 200), rbinom(800, 1, prob = 0.8)),           # 200 NAs in survival
group = rep(c("A", "B", "C", "D", "E"), each = 200)               # Group variable
# Expect warning when running rmm with missing values in the dataset
rmm(data = df_missing_values, Ps_col = Ps, outcome_col = survival, group_vars = "group", n_samples = 5, seed = 123)
testthat::test_that("rmm function handles large datasets without performance issues", {
# Test with a larger dataset to assess performance
df_large <- tibble::tibble(Ps = plogis(rnorm(100000, mean = 2, sd = 1.5)),
survival = rbinom(100000, 1, prob = 0.9))
result_large <- rmm(data = df_large, Ps_col = Ps, outcome_col = survival, n_samples = 1000)
difference <- as.numeric(difftime(end, begin, units = "secs"))
# Ensure the function runs without error and produces results
testthat::test_that("rm_bin_summary validates inputs correctly", {
testthat::expect_error(rm_bin_summary(data = NULL, Ps_col = Ps, outcome_col = survival))
testthat::expect_error(rm_bin_summary(data = df, outcome_col = survival))
testthat::expect_error(rm_bin_summary(data = df, Ps_col = Ps))
df_non_binary <- tibble::tibble(Ps = plogis(rnorm(1000, mean = 2, sd = 1.5)), survival = sample(1:3, 1000, replace = TRUE))
testthat::expect_error(rm_bin_summary(data = df_non_binary, Ps_col = Ps, outcome_col = survival))
testthat::expect_error(rm_bin_summary(data = df_non_numeric, Ps_col = Ps, outcome_col = survival))
df_ps_above_1 <- tibble::tibble(Ps = c(150, 80, 30), survival = c(1, 0, 1))
testthat::expect_error(rm_bin_summary(data = df_ps_above_1, Ps_col = Ps, outcome_col = survival))
testthat::test_that("nonlinear_bins produces correct bin data", {
testthat::expect_equal(nrow(bin_data$bin_stats), 10)  # assuming 5 bins
testthat::test_that("bootstrap data has the correct number of samples", {
infer::generate(reps = 100, type = "bootstrap")
testthat::test_that("bin statistics are calculated correctly", {
try_function <- rm_bin_summary(df, Ps, survival, n_samples = 5)
testthat::test_that("RMM is calculated correctly", {
rm_bin_summary(Ps, survival, n_samples = 5)
testthat::expect_true(all(rmm_result$population_RMM >= -1) || all(rmm_result$population_RMM <= 1))
testthat::test_that("confidence intervals are correctly computed in final RMM", {
df <- tibble::tibble(Ps = plogis(rnorm(10000, mean = 2, sd = 1.5)), survival = rbinom(10000, 1, prob = 0.9))
rmm_result <- rm_bin_summary(df, Ps, survival, n_samples = 100)
testthat::expect_true(all(rmm_result$population_RMM_UL > rmm_result$population_RMM_LL))  # CI upper should be greater than lower
testthat::test_that("RMM final data is correctly sorted by bin_number", {
rmm_result_final <- rm_bin_summary(df, Ps, survival, n_samples = 5)
testthat::expect_equal(max(rmm_result_final$bin_number), 10)  # Assuming 10 bins
testthat::test_that("rm_bin_summary validates group_vars correctly", {
group = sample(letters[1:5], 1000, replace = TRUE))
grouped_result <- rm_bin_summary(df, Ps, survival, group_vars = "group", n_samples = 5)
# Test invalid group_vars (non-existent column)
testthat::expect_error(rm_bin_summary(df, Ps, survival, group_vars = non_existent_col))
testthat::test_that("rm_bin_summary handles the seed argument correctly", {
result1 <- rm_bin_summary(df, Ps, survival, n_samples = 5, seed = 12345)
result2 <- rm_bin_summary(df, Ps, survival, n_samples = 5, seed = 12345)
# Ensure the results are the same for the same seed
# Test different seed values result in different outputs
result3 <- rm_bin_summary(df, Ps, survival, n_samples = 5, seed = 67890)
testthat::test_that("rm_bin_summary handles extreme edge cases for Ps values", {
# Test edge cases for Ps column (extremely low/high values)
df_extreme <- tibble::tibble(Ps = c(1e-10, 1, 1e+10), survival = c(1, 0, 1))
# Ensure that error is thrown with values above 1 or less than 0
testthat::expect_error(rm_bin_summary(df_extreme, Ps, survival, n_samples = 5))
testthat::test_that("rm_bin_summary produces error with invalid n_samples", {
# Invalid n_samples (non-integer, negative)
testthat::expect_error(rm_bin_summary(df, Ps, survival, n_samples = -1))
testthat::expect_error(rm_bin_summary(df, Ps, survival, n_samples = 3.5))
testthat::test_that("rm_bin_summary with missing group_vars argument", {
# Ensure no error when group_vars is not supplied
no_group_result <- rm_bin_summary(df, Ps, survival, n_samples = 5)