Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
76 changes: 38 additions & 38 deletions tests/testthat/test-simulations.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
expected_bre_fit <- list(
est.table = structure(
c(-0.60955243747617, -0.443501946207444, 0.736943004541776,
0.0104576873063189, 0.000414042620671129, 0.0123799088684966),
.Dim = 3:2,
.Dimnames = list(
est.table = matrix(
c(
-0.60955243747617, -0.443501946207444, 0.736943004541776,
0.0104576873063189, 0.000414042620671129, 0.0123799088684966
),
nrow = 3,
dimnames = list(
c("intersept", "log.Time", "Treatment"),
c("Estimate", "Pvalue")
)
Expand All @@ -14,52 +16,50 @@ expected_bre_fit <- list(

test_that("simulate_beta_data works", {
beta_data <- simulate_beta_random_effect_data()

# betareg can not fit random effect model so set the s2 to a small value (small random effect)
tdata <- data.frame(Y = beta_data$Y, beta_data$Z, SID = beta_data$subject_ind)
gy <- betareg::betareg(beta_data$Y ~ log.Time + as.factor(Treatment), data = tdata, type = "ML")
#print(summary(gy))
gy <- betareg::betareg(beta_data$Y ~ log.Time + as.factor(Treatment), data = tdata, type = "BC")
#print(summary(gy))
gy <- betareg::betareg(beta_data$Y ~ log.Time + as.factor(Treatment), data = tdata, type = "BR")
#print(summary(gy))

res <- fit_beta_random_effect(Z = beta_data$Z,
Y = beta_data$Y,
subject.ind = beta_data$subject_ind,
time.ind = beta_data$time_ind,
quad.n = 30,
verbose = FALSE)
res <- fit_beta_random_effect(
Z = beta_data$Z,
Y = beta_data$Y,
subject.ind = beta_data$subject_ind,
time.ind = beta_data$time_ind,
quad.n = 30,
verbose = FALSE
)

expect_equal(res, expected_bre_fit, tolerance = 1e-3)
})

expected_lre_fit <- list(
est.table = structure(
c(0.306795205483351, 0.280454254105502,
-0.667159092633291, 0.431194361789462, 0.266160176079596, 0.123214729652536),
.Dim = 3:2,
.Dimnames = list(c("intersept", "log.Time", "Treatment"), c("Estimate", "Pvalue"))
est.table = matrix(
c(
0.306795205483351, 0.280454254105502,
-0.667159092633291, 0.431194361789462, 0.266160176079596, 0.123214729652536
),
nrow = 3,
dimnames = list(c("intersept", "log.Time", "Treatment"), c("Estimate", "Pvalue"))
),
s1.est = 1.12114408844058
)

test_that("simulate_logistic_data works", {
logistic_data <- simulate_logistic_data()

tdata <- data.frame(Y = logistic_data$Y, logistic_data$X, SID = logistic_data$subject_ind)
lme.fit <- lme4::glmer(as.factor(logistic_data$Y) ~ log.Time + as.factor(Treatment) + (1 | SID),
data = tdata,
family = binomial,
control = lme4::glmerControl(optimizer = "bobyqa"),
nAGQ = 10)
tdata <- data.frame(
Y = logistic_data$Y, logistic_data$X, SID = logistic_data$subject_ind
)
lme.fit <- lme4::glmer(
as.factor(logistic_data$Y) ~ log.Time + as.factor(Treatment) + (1 | SID),
data = tdata,
family = binomial,
control = lme4::glmerControl(optimizer = "bobyqa"),
nAGQ = 10
)
summary(lme.fit)

res <- fit_logistic_random_effect(X = logistic_data$X,
Y = logistic_data$Y,
subject.ind = logistic_data$subject_ind,
time.ind = logistic_data$time_ind)
dput(res)

res <- fit_logistic_random_effect(
X = logistic_data$X,
Y = logistic_data$Y,
subject.ind = logistic_data$subject_ind,
time.ind = logistic_data$time_ind
)
expect_equal(res, expected_lre_fit, tolerance = 1e-3)
})
76 changes: 41 additions & 35 deletions tests/testthat/test-zibr.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
real_expected <- list(
logistic_est_table = structure(
logistic_est_table = matrix(
c(2.69732340911363, 0.200018071642455, 6.17105397782147e-06, 0.887710710500198),
.Dim = c(2L, 2L),
.Dimnames = list(
nrow = 2,
dimnames = list(
c("intersept", "Treatment"),
c("Estimate", "Pvalue")
)
),
logistic_s1_est = 3.27876357265477,
beta_est_table = structure(
beta_est_table = matrix(
c(-2.78605402671509, -0.32334269957996, 0, 0.206300170582503),
.Dim = c(2L, 2L),
.Dimnames = list(
nrow = 2,
dimnames = list(
c("intersept", "Treatment"),
c("Estimate", "Pvalue")
)
Expand All @@ -30,13 +30,15 @@ test_that("zibr main function works on package data", {
time_ind = ibd$Time
)

expected_names <- c("logistic_est_table",
"logistic_s1_est",
"beta_est_table",
"beta_s2_est",
"beta_v_est",
"loglikelihood",
"joint_p")
expected_names <- c(
"logistic_est_table",
"logistic_s1_est",
"beta_est_table",
"beta_s2_est",
"beta_v_est",
"loglikelihood",
"joint_p"
)
expect_equal(names(zibr_fit), expected_names)
expect_equal(zibr_fit, real_expected, tolerance = 1e-3)
})
Expand All @@ -55,19 +57,19 @@ sim <- simulate_zero_inflated_beta_random_effect_data(
)

sim_expected <- list(
logistic_est_table = structure(
logistic_est_table = matrix(
c(-0.571900346260645, 0.828072571379781, 0.0069577928092327, 0.00547006539016526),
.Dim = c(2L, 2L),
.Dimnames = list(
nrow = 2,
dimnames = list(
c("intersept", "var1"),
c("Estimate", "Pvalue")
)
),
logistic_s1_est = 1.06801391077711,
beta_est_table = structure(
beta_est_table = matrix(
c(-0.593090577296489, 0.591745582740125, 4.18162741963046e-05, 0.00169945318503251),
.Dim = c(2L, 2L),
.Dimnames = list(
nrow = 2,
dimnames = list(
c("intersept", "var1"),
c("Estimate", "Pvalue")
)
Expand All @@ -79,19 +81,19 @@ sim_expected <- list(
)

sim_expected_cov <- list(
logistic_est_table = structure(
logistic_est_table = matrix(
c(-0.571900346260645, 0.828072571379781, 0.0069577928092327, 0.00547006539016526),
.Dim = c(2L, 2L),
.Dimnames = list(
nrow = 2,
dimnames = list(
c("intersept", "var1"),
c("Estimate", "Pvalue")
)
),
logistic_s1_est = 1.06801391077711,
beta_est_table = structure(
beta_est_table = matrix(
c(-0.593090577296489, 0.591745582740125, 4.18162741963046e-05, 0.00169945318503251),
.Dim = c(2L, 2L),
.Dimnames = list(
nrow = 2,
dimnames = list(
c("intersept", "var1"),
c("Estimate", "Pvalue")
)
Expand All @@ -103,21 +105,25 @@ sim_expected_cov <- list(
)

test_that("zibr main function works on simulated data", {
zibr_fit <- zibr(logistic_cov = sim$X,
beta_cov = sim$Z,
Y = sim$Y,
subject_ind = sim$subject_ind,
time_ind = sim$time_ind)
zibr_fit <- zibr(
logistic_cov = sim$X,
beta_cov = sim$Z,
Y = sim$Y,
subject_ind = sim$subject_ind,
time_ind = sim$time_ind
)

expect_equal(zibr_fit, sim_expected, tolerance = 1e-3)
})

test_that("zibr main function works on simulated data with same covariates", {
zibr_fit <- zibr(logistic_cov = sim$X,
beta_cov = sim$X,
Y = sim$Y,
subject_ind = sim$subject_ind,
time_ind = sim$time_ind)
zibr_fit <- zibr(
logistic_cov = sim$X,
beta_cov = sim$X,
Y = sim$Y,
subject_ind = sim$subject_ind,
time_ind = sim$time_ind
)

expect_equal(zibr_fit, sim_expected_cov, tolerance = 1e-3)
})
Loading