Skip to content

Commit

Permalink
Merge pull request #37 from nutriverse:dev
Browse files Browse the repository at this point in the history
test calculate_coeff_r; fix #30
  • Loading branch information
ernestguevarra authored Dec 18, 2024
2 parents bec44db + d1d21c8 commit 4258391
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
1 change: 0 additions & 1 deletion R/07_calculate_coeff_r.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#'

calculate_coeff_r <- function(total_tem, sd) {

coeff_r <- (total_tem ^ 2) / sd

coeff_r
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-06_calculate_total_tem.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Tests for calculate_total_tem ------------------------------------------------

# Calculate intra-observer TEM
## Calculate intra-observer TEM
intra <- calculate_tem_cohort(
df = smartStd, m1 = "muac1", m2 = "muac2", index = "observer", n = 11
)

# Get inter-observer TEM
## Get inter-observer TEM
muacDF1 <- subset(
smartStd, select = c(-muac2, -weight1, -weight2, -height1, -height2)
)
Expand All @@ -14,7 +14,7 @@ muacDF2 <- subset(
smartStd, select = c(-muac1, -weight1, -weight2, -height1, -height2)
)

# Spread the dataset to wide format
## Spread the dataset to wide format
muacDF1 <- tidyr::spread(muacDF1, key = "observer", value = "muac1")
muacDF2 <- tidyr::spread(muacDF2, key = "observer", value = "muac2")
muacDF <- merge(muacDF1, muacDF2, by = "subject")
Expand Down
37 changes: 37 additions & 0 deletions tests/testthat/test-07_calculate_coeff_r.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Tests for calculate_coeff_r --------------------------------------------------

## Calculate intra-observer TEM
intra <- calculate_tem_cohort(
df = smartStd, m1 = "muac1", m2 = "muac2", index = "observer", n = 11
)

## Get inter-observer TEM
muacDF1 <- subset(
smartStd, select = c(-muac2, -weight1, -weight2, -height1, -height2)
)

muacDF2 <- subset(
smartStd, select = c(-muac1, -weight1, -weight2, -height1, -height2)
)

## Spread the dataset to wide format
muacDF1 <- tidyr::spread(muacDF1, key = "observer", value = "muac1")
muacDF2 <- tidyr::spread(muacDF2, key = "observer", value = "muac2")
muacDF <- merge(muacDF1, muacDF2, by = "subject")
inter <- calculate_team_tem(n = 10, k = 22, m = muacDF[ , 2:23])

total_tem <- calculate_total_tem(intra = intra$tem, inter = inter)

## Calculate sd
stdev <- calculate_sd(
measures = subset(smartStdLong, measure_type == "muac")$measure_value,
index = subset(smartStdLong, measure_type == "muac")$observer
)


test_that("calculate_coeff_r works as expected", {
expect_type(
calculate_coeff_r(total_tem = total_tem, sd = stdev$sd),
"double"
)
})

0 comments on commit 4258391

Please sign in to comment.