-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from ankemt/summary-20
Create a summary of statistics from the treatment ratio object
- Loading branch information
Showing
6 changed files
with
76 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#' Generate statistics for a treatment dataframe | ||
#' | ||
#' @param ratio_df resulting dataframe of the `treatment_ratio` function | ||
#' | ||
#' @return dataframe with summary statistics | ||
#' @export | ||
treatment_stats <- function(ratio_df){ | ||
|
||
df <- ratio_df |> | ||
dplyr::group_by(Metric_type, Parameter, Group) |> | ||
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) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
test_that("Summary is calculated correctly",{ | ||
load("output_treatment_ratio.Rda") | ||
|
||
statsum <- treatment_stats(output_treatment_ratio) | ||
expect_true("tbl_df" %in% class(statsum)) | ||
expect_equal(nrow(statsum), 288) | ||
|
||
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)) | ||
|
||
}) |