tests/testthat/test-simulate.R

context("data simulation")

test_that(
  "testing nimble distribution", {
    data <- tempo_simulate(n = 100, t = 365,
                           censor_intensity = 3,
                           beta_mu = c(-5, 0.5, -1, 0.3),
                           random_betas = c(1, 4),
                           beta_sd = c(0.23, 0.3),
                           covariates = NULL,
                           n_group = 4,
                           rho = c(-0.28))
    expect_true(is.list(data))
    
  
    data2 <- tempo_simulate(n = 100, t = 365,
                            censor_intensity = 3,
                            beta_mu = c(-5, 0.5, -1, 0.3),
                            random_betas = NULL,
                            beta_sd = NULL,
                            covariates = NULL,
                            n_group = NULL,
                            rho = NULL)
    expect_true(is.list(data2))
    
    data3 <- tempo_simulate(n = 100, t = 365,
                           censor_intensity = 3,
                           beta_mu = c(-5, 0.5, -1, 0.3),
                           random_betas = c(1),
                           beta_sd = c(0.23),
                           covariates = NULL,
                           n_group = 4,
                           rho = NULL)
    expect_true(is.list(data3))
    
    covariates <- list(a = matrix((1:365) / sd(1:365), nrow = 100, ncol = 365, byrow = TRUE),
                       b = matrix(rnorm(100 * 365), nrow = 100),
                       c = matrix(rnorm(100 * 365), nrow = 100))
    data3 <- tempo_simulate(n = 100, t = 365,
                            censor_intensity = 3,
                            beta_mu = c(-5, 0.5, -1, 0.3),
                            random_betas = c(1, 3),
                            beta_sd = c(0.23, 0.2),
                            covariates = covariates,
                            n_group = 4,
                            rho = NULL)
    expect_true(is.list(data3))
    
    # error for n_groups > n
    expect_error(
      tempo_simulate(n = 10, t = 365,
                     censor_intensity = 3,
                     beta_mu = c(-5, 0.5, -1, 0.3),
                     random_betas = c(1, 3),
                     beta_sd = c(0.23, 0.2),
                     covariates = NULL,
                     n_group = 50,
                     rho = NULL)
      )
  }
)
vlandau/tempo documentation built on March 18, 2020, 12:04 a.m.