tests/testthat/test-inctools.R

test_that("mdri estimation works", {
  expect_equal(mdrical(data=excalibdata,
                       subid_var = "SubjectID",
                       time_var = "DaysSinceEDDI",
                       recency_cutoff_time = 730.5,
                       inclusion_time_threshold = 800,
                       functional_forms = c("logit_cubic"),
                       recency_rule = "binary_data",
                       recency_vars = "Recent",
                       n_bootstraps = 0,
                       plot = FALSE,
                       parallel = FALSE)$MDRI$PE, 
               235.8039,
               tolerance = 1e-05)
  expect_equal(mdrical(data=excalibdata,
                       subid_var = "SubjectID",
                       time_var = "DaysSinceEDDI",
                       recency_cutoff_time = 730.5,
                       inclusion_time_threshold = 800,
                       functional_forms = c("cloglog_linear"),
                       recency_rule = "binary_data",
                       recency_vars = "Recent",
                       n_bootstraps = 0,
                       plot = FALSE,
                       parallel = FALSE)$MDRI$PE, 
               248.1445,
               tolerance = 1e-05)
  expect_equal(mdrical(data=excalibdata,
                       subid_var = "SubjectID",
                       time_var = "DaysSinceEDDI",
                       recency_cutoff_time = 730.5,
                       inclusion_time_threshold = 800,
                       functional_forms = c("logit_cubic"),
                       recency_rule = "independent_thresholds",
                       recency_vars = c("Result","VL"),
                       recency_params = c(10,0,1000,1),
                       n_bootstraps = 0,
                       plot = FALSE,
                       parallel = FALSE)$MDRI$PE, 
               259.2234,
               tolerance = 1e-05)
  expect_equal(mdrical(data=excalibdata,
                       subid_var = "SubjectID",
                       time_var = "DaysSinceEDDI",
                       recency_cutoff_time = 730.5,
                       inclusion_time_threshold = 800,
                       functional_forms = c("cloglog_linear"),
                       recency_rule = "independent_thresholds",
                       recency_vars = c("Result","VL"),
                       recency_params = c(10,0,1000,1),
                       n_bootstraps = 0,
                       plot = FALSE,
                       parallel = FALSE)$MDRI$PE, 
               271.7752,
               tolerance = 1e-05)
  expect_equal(class(mdrical(data=excalibdata,
                             subid_var = "SubjectID",
                             time_var = "DaysSinceEDDI",
                             recency_cutoff_time = 730.5,
                             inclusion_time_threshold = 800,
                             functional_forms = c("cloglog_linear"),
                             recency_rule = "independent_thresholds",
                             recency_vars = c("Result","VL"),
                             recency_params = c(10,0,1000,1),
                             n_bootstraps = 0,
                             plot = TRUE)$Plots$cloglog_linear), 
               c("gg","ggplot"))
  expect_equal(class(mdrical(data=excalibdata,
                             subid_var = "SubjectID",
                             time_var = "DaysSinceEDDI",
                             recency_cutoff_time = 730.5,
                             inclusion_time_threshold = 800,
                             functional_forms = c("logit_cubic"),
                             recency_rule = "independent_thresholds",
                             recency_vars = c("Result","VL"),
                             recency_params = c(10,0,1000,1),
                             n_bootstraps = 0,
                             plot = TRUE)$Plots$logit_cubic), 
               c("gg","ggplot"))
})

test_that("mdri bootstrapping works", {
  skip_on_cran()
  skip_if(as.numeric(R.Version()$major) == 3 & as.numeric(R.Version()$minor) < 6, 
          message = "Bootstrapping tests skipped on R versions before 3.6") # Workaround for unexplained failures
  expect_equal({
    mdri <- mdrical(data=excalibdata,
                    subid_var = "SubjectID",
                    time_var = "DaysSinceEDDI",
                    recency_cutoff_time = 730.5,
                    inclusion_time_threshold = 800,
                    functional_forms = c("logit_cubic"),
                    recency_rule = "binary_data",
                    recency_vars = "Recent",
                    n_bootstraps = 100,
                    random_seed = 123,
                    plot = FALSE,
                    parallel = FALSE,
                    output_bs_parms = FALSE)
    unname(c(mdri$MDRI$SE, mdri$MDRI$CI_LB, mdri$MDRI$CI_UB))
  },
  c(12.4942, 212.1693, 257.5222),
  tolerance = 1e-05)
  expect_equal({
    mdri <- mdrical(data=excalibdata,
                    subid_var = "SubjectID",
                    time_var = "DaysSinceEDDI",
                    recency_cutoff_time = 730.5,
                    inclusion_time_threshold = 800,
                    functional_forms = c("cloglog_linear"),
                    recency_rule = "binary_data",
                    recency_vars = "Recent",
                    n_bootstraps = 100,
                    random_seed = 123,
                    plot = FALSE,
                    parallel = FALSE,
                    output_bs_parms = FALSE)
    unname(c(mdri$MDRI$SE, mdri$MDRI$CI_LB, mdri$MDRI$CI_UB))
  },
  c(12.58502, 221.64980, 268.07910),
  tolerance = 1e-05)
  expect_equal({
    mdri <- mdrical(data=excalibdata,
                    subid_var = "SubjectID",
                    time_var = "DaysSinceEDDI",
                    recency_cutoff_time = 730.5,
                    inclusion_time_threshold = 800,
                    functional_forms = c("logit_cubic"),
                    recency_rule = "binary_data",
                    recency_vars = "Recent",
                    n_bootstraps = 100,
                    random_seed = 123,
                    plot = FALSE,
                    parallel = FALSE,
                    output_bs_parms = TRUE)
    c(nrow(mdri$BSparms$logit_cubic),
      mean(mdri$BSparms$logit_cubic$beta0),
      mean(mdri$BSparms$logit_cubic$beta1),
      mean(mdri$BSparms$logit_cubic$beta2),
      mean(mdri$BSparms$logit_cubic$beta3))
  },
  c(100, 2.243834, -0.01571105, 2.212851e-05, -1.509442e-08),
  tolerance = 1e-05)
  expect_equal({
    mdri <- mdrical(data=excalibdata,
                    subid_var = "SubjectID",
                    time_var = "DaysSinceEDDI",
                    recency_cutoff_time = 730.5,
                    inclusion_time_threshold = 800,
                    functional_forms = c("cloglog_linear"),
                    recency_rule = "binary_data",
                    recency_vars = "Recent",
                    n_bootstraps = 100,
                    random_seed = 123,
                    plot = FALSE,
                    parallel = FALSE,
                    output_bs_parms = TRUE)
    c(nrow(mdri$BSparms$cloglog_linear),
      mean(mdri$BSparms$cloglog_linear$beta0),
      mean(mdri$BSparms$cloglog_linear$beta1))
  },
  c(100, 4.2747332, -0.9427134),
  tolerance = 1e-05)
  # Run estimation and perform a few tests on the result (is this bad?)
  expect_equal({
    mdri_parallel <- mdrical(data=excalibdata,
                             subid_var = "SubjectID",
                             time_var = "DaysSinceEDDI",
                             recency_cutoff_time = 730.5,
                             inclusion_time_threshold = 800,
                             functional_forms = c("cloglog_linear", "logit_cubic"),
                             recency_rule = "binary_data",
                             recency_vars = "Recent",
                             n_bootstraps = 500,
                             random_seed = 123,
                             plot = FALSE,
                             parallel = TRUE,
                             cores = 2,
                             output_bs_parms = FALSE)
    unname(c(mdri_parallel$MDRI$SE[1], mdri_parallel$MDRI$SE[2],
      mdri_parallel$MDRI$CI_LB[1], mdri_parallel$MDRI$CI_LB[2], 
      mdri_parallel$MDRI$CI_UB[1], mdri_parallel$MDRI$CI_UB[2]))
  },
  c(13.05429, 13.01022, 221.56480, 209.66825, 271.29934, 259.05984),
  tolerance = 1e-05)
  expect_equal({
    mdri_parallel_bsparams <- mdrical(data=excalibdata,
                                      subid_var = "SubjectID",
                                      time_var = "DaysSinceEDDI",
                                      recency_cutoff_time = 730.5,
                                      inclusion_time_threshold = 800,
                                      functional_forms = c("cloglog_linear", "logit_cubic"),
                                      recency_rule = "binary_data",
                                      recency_vars = "Recent",
                                      n_bootstraps = 250,
                                      random_seed = NULL,
                                      plot = FALSE,
                                      parallel = TRUE,
                                      cores = 2,
                                      output_bs_parms = TRUE)
    c(nrow(mdri_parallel_bsparams$BSparms$cloglog_linear), 
      nrow(mdri_parallel_bsparams$BSparms$logit_cubic))
  },
  c(250,250)
  )
})

test_that("mdrical() error messages work", {
  expect_error(
    mdrical(subid_var = "SubjectID",
            time_var = "DaysSinceEDDI",
            recency_cutoff_time = 730.5,
            inclusion_time_threshold = 800,
            functional_forms = c("cloglog_linear"),
            recency_rule = "binary_data",
            recency_vars = "Recent",
            n_bootstraps = 0,
            plot = FALSE,
            parallel = FALSE),
    "No input data has been specified", fixed = TRUE
  )
  expect_error(
    mdrical(data=excalibdata,
            time_var = "DaysSinceEDDI",
            recency_cutoff_time = 730.5,
            inclusion_time_threshold = 800,
            functional_forms = c("cloglog_linear"),
            recency_rule = "binary_data",
            recency_vars = "Recent",
            n_bootstraps = 0,
            plot = FALSE,
            parallel = FALSE),
    "No subject identifier has been specified", fixed = TRUE
  )
  expect_error(
    mdrical(data=excalibdata,
            subid_var = "SubjectID",
            time_var = "DaysSinceEDDI",
            recency_cutoff_time = 730.5,
            inclusion_time_threshold = 800,
            functional_forms = c("logit_cubic"),
            recency_rule = "garbage_rule",
            recency_vars = "Recent",
            n_bootstraps = 0,
            plot = FALSE,
            parallel = FALSE),
    "Please specify a valid recency rule", fixed = TRUE
  )
  expect_error(
    mdrical(data=excalibdata,
            subid_var = "SubjectID",
            time_var = "DaysSinceEDDI",
            recency_cutoff_time = 730.5,
            inclusion_time_threshold = 800,
            functional_forms = c("logit_cubic"),
            recency_rule = "binary_data",
            recency_vars = c("Result","VL"),
            recency_params = c(10,0,1000,1),
            n_bootstraps = 0,
            plot = FALSE,
            parallel = FALSE),
    "Binary data should have one recency variable", fixed = TRUE
  )
  expect_error(
    mdrical(data=excalibdata,
            subid_var = "SubjectID",
            time_var = "DaysSinceEDDI",
            recency_cutoff_time = 730.5,
            inclusion_time_threshold = 800,
            functional_forms = c("logit_cubic"),
            recency_rule = "independent_thresholds",
            recency_vars = "Recent",
            recency_params =c(10,0,1000,1),
            n_bootstraps = 0,
            plot = FALSE,
            parallel = FALSE),
    "The number of recency variables must match the number of recency paramaters", fixed = TRUE
  )
  expect_error(
    mdrical(data=excalibdata,
            subid_var = "SubjectID",
            time_var = "DaysSinceEDDI",
            recency_cutoff_time = 730.5,
            inclusion_time_threshold = 800,
            functional_forms = c("logit"),
            recency_rule = "binary_data",
            recency_vars = "Recent",
            n_bootstraps = 0,
            plot = FALSE,
            parallel = FALSE),
    "Please specify valid functional form(s)", fixed = TRUE
  )
})

test_that("frr estimation works", {
  expect_equal(frrcal(data=excalibdata,
                      subid_var = "SubjectID",
                      time_var = "DaysSinceEDDI",
                      recency_cutoff_time = 730.5,
                      recency_rule = "independent_thresholds",
                      recency_vars = c("Result","VL"),
                      recency_params = c(10,0,1000,1),
                      alpha = 0.05)$FRRest, 0.03007519)
  expect_equal(frrcal(data=excalibdata,
                      subid_var = "SubjectID",
                      time_var = "DaysSinceEDDI",
                      recency_cutoff_time = 730.5,
                      recency_rule = "independent_thresholds",
                      recency_vars = c("Result","VL"),
                      recency_params = c(10,0,1000,1),
                      alpha = 0.05,
                      method = "probit")$ci_method, "probit")
  expect_equal(frrcal(data=excalibdata,
                      subid_var = "SubjectID",
                      time_var = "DaysSinceEDDI",
                      recency_cutoff_time = 730.5,
                      recency_rule = "independent_thresholds",
                      recency_vars = c("Result","VL"),
                      recency_params = c(10,0,1000,1),
                      alpha = 0.05,
                      method = "probit")$CI_LB, 0.01460227)
  expect_equal(frrcal(data=excalibdata,
                      subid_var = "SubjectID",
                      time_var = "DaysSinceEDDI",
                      recency_cutoff_time = 730.5,
                      recency_rule = "independent_thresholds",
                      recency_vars = c("Result","VL"),
                      recency_params = c(10,0,1000,1),
                      alpha = 0.05,
                      method = "probit")$CI_UB, 0.05720647)
})

test_that("frrcal() error messages work", {
  expect_error(
    frrcal(subid_var = "SubjectID",
           time_var = "DaysSinceEDDI",
           recency_cutoff_time = 730.5,
           recency_rule = "binary_data",
           recency_vars = "Recent"),
    "No dataframe provided", fixed = TRUE
  )
  expect_error(
    frrcal(data=excalibdata,
           time_var = "DaysSinceEDDI",
           recency_cutoff_time = 730.5,
           recency_rule = "binary_data",
           recency_vars = "Recent"),
    "Subject identifier must be specified", fixed = TRUE
  )
  expect_error(
    frrcal(data=excalibdata,
           subid_var = "SubjectID",
           recency_cutoff_time = 730.5,
           recency_rule = "binary_data",
           recency_vars = "Recent"),
    "Time variable must be specified", fixed = TRUE
  )
  expect_error(
    frrcal(data=excalibdata,
           subid_var = "GarbageVar",
           time_var = "DaysSinceEDDI",
           recency_cutoff_time = 730.5,
           recency_rule = "binary_data",
           recency_vars = "Recent"),
    "There is no column GarbageVar in the data frame", fixed = TRUE
  )
  expect_error(
    frrcal(data=excalibdata,
           subid_var = "SubjectID",
           time_var = "GarbageVar",
           recency_cutoff_time = 730.5,
           recency_rule = "binary_data",
           recency_vars = "Recent"),
    "There is no column GarbageVar in the data frame", fixed = TRUE
  )
  expect_error(
    frrcal(data=excalibdata,
           subid_var = "SubjectID",
           time_var = "DaysSinceEDDI",
           recency_cutoff_time = 730.5,
           recency_rule = "binary_data",
           recency_vars = "GarbageVar"),
    "There is no column GarbageVar in the data frame", fixed = TRUE
  )
  expect_error(
    frrcal(data=excalibdata,
           subid_var = "SubjectID",
           time_var = "DaysSinceEDDI",
           recency_cutoff_time = 730.5,
           recency_rule = "garbage_rule",
           recency_vars = "Recent"),
    "Please specify a valid recency rule", fixed = TRUE
  )
  expect_error(
    frrcal(data=excalibdata,
           subid_var = "SubjectID",
           time_var = "DaysSinceEDDI",
           recency_cutoff_time = 730.5,
           recency_rule = "binary_data",
           recency_vars = c("Result","VL"),
           recency_params = c(10,0,1000,1)),
    "Binary data should be specified in one recency (outcome) variable.", fixed = TRUE
  )
  expect_error(
    frrcal(data=excalibdata,
           subid_var = "SubjectID",
           time_var = "DaysSinceEDDI",
           recency_cutoff_time = 730.5,
           recency_rule = "independent_thresholds",
           recency_vars = "Recent",
           recency_params =c(10,0,1000,1)),
    "The number of recency variables must match the number of recency paramaters.", fixed = TRUE
  )
  expect_error(
    frrcal(data=excalibdata,
           subid_var = "SubjectID",
           time_var = "DaysSinceEDDI",
           recency_cutoff_time = 730.5,
           recency_rule = "independent_thresholds",
           recency_vars = c("Result","VL"),
           recency_params = c(10,0,1000,1),
           alpha = 0.05,
           method = NULL),
    "Confidence interval method must be specified", fixed = TRUE        
  )
  expect_error(
    frrcal(data=excalibdata,
           subid_var = "SubjectID",
           time_var = "DaysSinceEDDI",
           recency_cutoff_time = 730.5,
           recency_rule = "independent_thresholds",
           recency_vars = c("Result","VL"),
           recency_params = c(10,0,1000,1),
           alpha = 0.05,
           method = c("exact", "ac")),
           "Exactly one confidence interval method must be specified", fixed = TRUE        
    )
    expect_error(
      frrcal(data=excalibdata,
             subid_var = "SubjectID",
             time_var = "DaysSinceEDDI",
             recency_cutoff_time = 730.5,
             recency_rule = "independent_thresholds",
             recency_vars = c("Result","VL"),
             recency_params = c(10,0,1000,1),
             alpha = 0.05,
             method = "garbage"),
             "Confidence interval method must be one of 'exact', 'ac', 'asymptotic', 'wilson', 'prop.test', 'bayes', 'logit', 'cloglog', 'probit'. See help of binom::binom.test() for further details", fixed = TRUE        
      )
})
    
    test_that("incidence estimation works", {
      expect_equal(incprops(PrevH = 0.20, 
                            RSE_PrevH = 0.028, 
                            PrevR = 0.10, 
                            RSE_PrevR = 0.09,
                            Boot = FALSE, 
                            MDRI = 200, 
                            RSE_MDRI = 0.05,
                            FRR = 0.01, 
                            RSE_FRR = 0.2, 
                            BigT = 730.5, 
                            debug = FALSE)$Incidence.Statistics$Incidence, 
                   0.04264836)
      expect_equal(incprops(PrevH = c(0.20,0.21,0.18), 
                            RSE_PrevH = c(0.028,0.03,0.022),
                            PrevR = c(0.10,0.13,0.12), 
                            RSE_PrevR = c(0.094,0.095,0.05),
                            Boot = FALSE, 
                            BMest = 'MDRI.FRR.indep',
                            MDRI = c(200,180,180), 
                            RSE_MDRI = c(0.05,0.07,0.06),
                            FRR = c(0.01,0.009,0.02), 
                            RSE_FRR = c(0.2,0.2,0.1), 
                            BigT = 730.5)$Incidence.Difference.Statistics$p_value,
                   c(0.01491562,0.39928244,0.01491562,0.05327965,0.39928244,0.05327965))
    })
    
    test_that("inccounts() and incprops() give the same answers", {
      expect_equal(inccounts(N = 10000,
                             N_H = 1000,
                             N_testR = 990,
                             N_R = 99,
                             DE_H = 1.2,
                             DE_R = 1.2,
                             Boot = FALSE,
                             alpha = 0.05,
                             MDRI= 200,
                             RSE_MDRI = 0.1,
                             FRR = 0.01,
                             RSE_FRR = 0.25,
                             BigT = 730.5,
                             Covar_HR = 0,
                             debug = FALSE)$Incidence.Statistics$Incidence,
                   incprops(PrevH = 0.1, 
                            RSE_PrevH = 0.03286335,
                            PrevR = 0.1, 
                            RSE_PrevR = 0.1044466,
                            Boot = FALSE,
                            alpha = 0.05,
                            MDRI= 200,
                            RSE_MDRI = 0.1,
                            FRR = 0.01,
                            RSE_FRR = 0.25,
                            BigT = 730.5,
                            Covar_HR = 0,
                            debug = FALSE)$Incidence.Statistics$Incidence)
      expect_equal(inccounts(N = 10000,
                             N_H = 1000,
                             N_testR = 990,
                             N_R = 99,
                             DE_H = 1.2,
                             DE_R = 1.2,
                             Boot = FALSE,
                             alpha = 0.05,
                             MDRI= 200,
                             RSE_MDRI = 0.1,
                             FRR = 0.01,
                             RSE_FRR = 0.25,
                             BigT = 730.5,
                             Covar_HR = 0,
                             debug = FALSE)$Annual.Risk.of.Infection$ARI,
                   incprops(PrevH = 0.1, 
                            RSE_PrevH = 0.03286335,
                            PrevR = 0.1, 
                            RSE_PrevR = 0.1044466,
                            Boot = FALSE,
                            alpha = 0.05,
                            MDRI= 200,
                            RSE_MDRI = 0.1,
                            FRR = 0.01,
                            RSE_FRR = 0.25,
                            BigT = 730.5,
                            Covar_HR = 0,
                            debug = FALSE)$Annual.Risk.of.Infection$ARI)  
    })
    
    test_that("power calculation works", {
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            n1 = 5000, 
                            n2 = 5000, 
                            alpha = 0.05, 
                            Power = "out", 
                            SS = NULL,
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "same.test", 
                            MDRI = 200,
                            RSE_MDRI = 0.05, 
                            FRR = 0.01, 
                            RSE_FRR = 0.20, 
                            BigT = 730.5)$Inc.Difference.Statistics$Power,
                   0.8569811,
                   tolerance = 1e-07)
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            n1 = 5000, 
                            n2 = 5000, 
                            alpha = 0.05, 
                            Power = "out", 
                            SS = NULL,
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "same.test", 
                            MDRI = 200,
                            RSE_MDRI = 0.05, 
                            FRR = 0.01, 
                            RSE_FRR = 0.20, 
                            BigT = 730.5)$Inc.Difference.Statistics$RSE_deltaI,
                   0.3303799,
                   tolerance = 1e-07)
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            n1 = 5000, 
                            n2 = 5000, 
                            alpha = 0.05, 
                            Power = "out", 
                            SS = NULL,
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "same.test", 
                            MDRI = 200,
                            RSE_MDRI = 0.05, 
                            FRR = 0.01, 
                            RSE_FRR = 0.20, 
                            BigT = 730.5)$Inc.Difference.Statistics$RSE_deltaI.infSS,
                   0.05244642,
                   tolerance = 1e-07)
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            alpha = 0.05, 
                            Power = 0.8, 
                            SS = "out",
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "same.test", 
                            MDRI = 200,
                            RSE_MDRI = 0.05, 
                            FRR = 0.01, 
                            RSE_FRR = 0.20, 
                            BigT = 730.5)$Minimum.Common.SS,
                   4268)
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            n1 = 5000, 
                            n2 = 5000, 
                            alpha = 0.05, 
                            Power = "out", 
                            SS = NULL,
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "FRR.indep",
                            MDRI = 200,
                            RSE_MDRI = 0.05, 
                            FRR = c(0.01, 0.02), 
                            RSE_FRR = c(0.20, 0.15),  
                            BigT = 730.5)$Inc.Difference.Statistics$Power,
                   0.8238909,
                   tolerance = 1e-07)
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            n1 = 5000, 
                            n2 = 5000, 
                            alpha = 0.05, 
                            Power = "out", 
                            SS = NULL,
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "FRR.indep", 
                            MDRI = 200,
                            RSE_MDRI = 0.05, 
                            FRR = c(0.01, 0.02), 
                            RSE_FRR = c(0.20, 0.15), 
                            BigT = 730.5)$Inc.Difference.Statistics$RSE_deltaI,
                   0.3459897,
                   tolerance = 1e-07)
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            n1 = 5000, 
                            n2 = 5000, 
                            alpha = 0.05, 
                            Power = "out", 
                            SS = NULL,
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "FRR.indep", 
                            MDRI = 200,
                            RSE_MDRI = 0.05, 
                            FRR = c(0.01, 0.02), 
                            RSE_FRR = c(0.20, 0.15), 
                            BigT = 730.5)$Inc.Difference.Statistics$RSE_deltaI.infSS,
                   0.07965797,
                   tolerance = 1e-07)
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            alpha = 0.05, 
                            Power = 0.8, 
                            SS = "out",
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "FRR.indep", 
                            MDRI = 200,
                            RSE_MDRI = 0.05, 
                            FRR = c(0.01, 0.02), 
                            RSE_FRR = c(0.20, 0.15),  
                            BigT = 730.5)$Minimum.Common.SS,
                   4683)
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            n1 = 5000, 
                            n2 = 5000, 
                            alpha = 0.05, 
                            Power = "out", 
                            SS = NULL,
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "MDRI.FRR.indep",
                            MDRI = c(200, 180),
                            RSE_MDRI = c(0.05, 0.1), 
                            FRR = c(0.01, 0.02), 
                            RSE_FRR = c(0.20, 0.15),  
                            BigT = 730.5)$Inc.Difference.Statistics$Power,
                   0.6818551,
                   tolerance = 1e-07)
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            n1 = 5000, 
                            n2 = 5000, 
                            alpha = 0.05, 
                            Power = "out", 
                            SS = NULL,
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "MDRI.FRR.indep", 
                            MDRI = c(200, 180),
                            RSE_MDRI = c(0.05, 0.1), 
                            FRR = c(0.01, 0.02), 
                            RSE_FRR = c(0.20, 0.15), 
                            BigT = 730.5)$Inc.Difference.Statistics$RSE_deltaI,
                   0.4110394,
                   tolerance = 1e-07)
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            n1 = 5000, 
                            n2 = 5000, 
                            alpha = 0.05, 
                            Power = "out", 
                            SS = NULL,
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "MDRI.FRR.indep", 
                            MDRI = c(200, 180),
                            RSE_MDRI = c(0.05, 0.1),
                            FRR = c(0.01, 0.02), 
                            RSE_FRR = c(0.20, 0.15), 
                            BigT = 730.5)$Inc.Difference.Statistics$RSE_deltaI.infSS,
                   0.2196649,
                   tolerance = 1e-07)
      expect_equal(incpower(I1 = 0.05, 
                            I2 = 0.03, 
                            PrevH1 = 0.20, 
                            PrevH2 = 0.20,
                            alpha = 0.05, 
                            Power = 0.8, 
                            SS = "out",
                            DE_H = c(1,1.1), 
                            DE_R = 1, 
                            BMest = "MDRI.FRR.indep", 
                            MDRI = c(200, 180),
                            RSE_MDRI = c(0.05, 0.1), 
                            FRR = c(0.01, 0.02), 
                            RSE_FRR = c(0.20, 0.15),  
                            BigT = 730.5)$Minimum.Common.SS,
                   7625)
      expect_equal(incpower(I1 = 0.05,
                            I2 = 0.03,
                            PrevH1 = 0.20,
                            PrevH2 = 0.20,
                            n1 = "out",
                            n2 = 5000,
                            SS = "out",
                            alpha = 0.05,
                            Power = 0.8,
                            DE_H = c(1.2, 1.3),
                            DE_R = 1,
                            BMest = "same.test",
                            MDRI = 200,
                            RSE_MDRI = 0.05,
                            FRR = 0.01,
                            RSE_FRR = 0.20,
                            BigT = 730.5)$Minimum.SS,
                   4027)
      expect_equal(incpower(I1 = 0.05,
                            I2 = 0.03,
                            PrevH1 = 0.20,
                            PrevH2 = 0.20,
                            n1 = 5000,
                            n2 = "out",
                            SS = "out",
                            alpha = 0.05,
                            Power = 0.8,
                            DE_H = c(1.2, 1.3),
                            DE_R = 1,
                            BMest = "same.test",
                            MDRI = 200,
                            RSE_MDRI = 0.05,
                            FRR = 0.01,
                            RSE_FRR = 0.20,
                            BigT = 730.5)$Minimum.SS,
                   3608)
      expect_equal(incpower(I1 = 0.05,
                            I2 = 0.03,
                            PrevH1 = 0.20,
                            PrevH2 = 0.20,
                            n1 = "out",
                            n2 = 5000,
                            SS = "out",
                            alpha = 0.05,
                            Power = 0.8,
                            DE_H = c(1.2, 1.3),
                            DE_R = 1,
                            BMest = "FRR.indep",
                            MDRI = 200,
                            RSE_MDRI = 0.05,
                            FRR = c(0.01, 0.02),
                            RSE_FRR = c(0.20, 0.15),
                            BigT = 730.5)$Minimum.SS,
                   4615)
      expect_equal(incpower(I1 = 0.05,
                            I2 = 0.03,
                            PrevH1 = 0.20,
                            PrevH2 = 0.20,
                            n1 = 5000,
                            n2 = "out",
                            SS = "out",
                            alpha = 0.05,
                            Power = 0.8,
                            DE_H = c(1.2, 1.3),
                            DE_R = 1,
                            BMest = "FRR.indep",
                            MDRI = 200,
                            RSE_MDRI = 0.05,
                            FRR = c(0.01, 0.02),
                            RSE_FRR = c(0.20, 0.15),
                            BigT = 730.5)$Minimum.SS,
                   4488)
      expect_equal(incpower(I1 = 0.05,
                            I2 = 0.03,
                            PrevH1 = 0.20,
                            PrevH2 = 0.20,
                            n1 = "out",
                            n2 = 5000,
                            SS = "out",
                            alpha = 0.05,
                            Power = 0.8,
                            DE_H = c(1.2, 1.3),
                            DE_R = 1,
                            BMest = "MDRI.FRR.indep",
                            MDRI = c(200, 180),
                            RSE_MDRI = c(0.05, 0.1),
                            FRR = c(0.01, 0.02),
                            RSE_FRR = c(0.20, 0.15), 
                            BigT = 730.5)$Minimum.SS,
                   14470)
      expect_equal(incpower(I1 = 0.05,
                            I2 = 0.03,
                            PrevH1 = 0.20,
                            PrevH2 = 0.20,
                            n1 = 5000,
                            n2 = "out",
                            SS = "out",
                            alpha = 0.05,
                            Power = 0.8,
                            DE_H = c(1.2, 1.3),
                            DE_R = 1,
                            BMest = "MDRI.FRR.indep",
                            MDRI = c(200, 180),
                            RSE_MDRI = c(0.05, 0.1),
                            FRR = c(0.01, 0.02),
                            RSE_FRR = c(0.20, 0.15),
                            BigT = 730.5)$Minimum.SS,
                   22579)
    })
    
    
SACEMA/inctools documentation built on Dec. 18, 2021, 11:56 a.m.