Skip to content

Commit

Permalink
add further columns and a bunch more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bvreede committed Dec 2, 2022
1 parent b6ea6dc commit 6b3f7a4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 4 additions & 2 deletions R/treatment_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ treatment_stats <- function(ratio_df){

df <- ratio_df |>
dplyr::group_by(Group, Metric_type, Parameter) |>
dplyr::summarize(Ratio_avg = mean(Treatment_ratio),
Ratio_stdv = stats::sd(Treatment_ratio))
dplyr::summarize(n_wells = dplyr::n(),
Ratio_avg = mean(Treatment_ratio, na.rm=T),
Ratio_stdv = stats::sd(Treatment_ratio),
Ratio_SEM = stats::sd(Treatment_ratio)/sqrt(n_wells))
return(df)
}
28 changes: 27 additions & 1 deletion tests/testthat/test-treatment_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,31 @@ test_that("Summary is calculated correctly",{
statsum <- treatment_stats(output_treatment_ratio)
expect_true("tbl_df" %in% class(statsum))
expect_equal(nrow(statsum), 288)
expect_equal(ncol(statsum), 5)

expected_cols <- c("Ratio_avg",
"Ratio_stdv",
"Ratio_SEM",
"n_wells",
"Group",
"Metric_type",
"Parameter")
for(cname in expected_cols){
expect_true(cname %in% names(statsum),
info=paste("Variable:",cname))
}

# there are 8 wells per group in the example data
expect_true(mean(statsum$n_wells) == 8)

# check some values
vals <- statsum[statsum$Parameter == "Mean Firing Rate (Hz)",]$Ratio_SEM
vals <- round(vals, digits = 8)
known_vals <- c(0.15674431,
0.04957502,
0.09320916,
0.12364473,
0.28510038,
0.12974997)
expect_true(all(known_vals %in% vals))

})

0 comments on commit 6b3f7a4

Please sign in to comment.