Evaluation of the rate of change in count and intensity across brain areas. The criterion is set by two conditions: first condition based on consistency (i.e. change in the same direction across samples), and the second condition based on effect sizes (i.e. minimum effect size for the rate of change to be of interest). The function outputs a dataframe with the comparison performed, the brain area ("my_grouping") and towards which strategy (more intensity or more count) the brain area met the criteria.

find_changed_strategy(
  region_df,
  consistency_n_samples,
  comparison_group,
  min_change_rate = 1
)

Arguments

region_df

region_based dataframe. Each row is a brain area ("my_grouping") per sample ("sample_id"), where corrected cell count ("cells_perthousand") and average maximum intensity of the protein of interest ("intensity") have been summarized. These variables have been preprocessed to "cells_perthousand_box_scaled" and "intensity_box_scaled". The samples belong to experimental groups ("group") and were processed in batches ("batch", i.e. one sample per group). This data frame can be the output of preprocess_per_region().

consistency_n_samples

number of samples which require to have consistent results in (at least one) experimental group.

comparison_group

group against which comparison are made.

min_change_rate

minimum change in rate between comparison and experimental groups. Defaults to 1, i.e. any change.

Value

Examples

# prepare dataframe x <- data.frame( batch = rep(c(1,1,2,2), each = 5), group = rep(c("control", "exp", "exp", "control"), each = 5), sample_id = rep(c("a", "b", "c", "d"), each = 5), my_grouping = rep(c("CA1", "CA2", "CA3", "DG", "BLA"), 4), intensity = sample(10000, 20, replace = TRUE), cells_perthousand = abs(rnorm(20)) ) x$intensity_box_scaled <- scale(x$intensity) x$cells_perthousand_box_scaled <- scale(x$cells_perthousand) y <- find_changed_strategy(x, 2, "control")
#> Error in region_df %>% dplyr::mutate(group = ifelse(group == comparison_group, "base", as.character(group))) %>% dplyr::group_by(my_grouping, batch, group) %>% dplyr::summarize(count = median(cells_perthousand_box_scaled, na.rm = T), intensity = median(intensity_box_scaled, na.rm = T)) %>% tidyr::pivot_wider(id_cols = c(my_grouping, batch), names_from = group, values_from = c(count, intensity)) %>% dplyr::mutate(dplyr::across(dplyr::starts_with("count_"), ~{ .x - count_base }), dplyr::across(dplyr::starts_with("intensity_"), ~{ .x - intensity_base})) %>% dplyr::select(-c(count_base, intensity_base)) %>% dplyr::select(my_grouping, batch, starts_with("count_"), starts_with("intensity_")) %>% tidyr::pivot_longer(cols = -c(my_grouping, batch), names_to = "comparison", values_to = "difference") %>% tidyr::separate(comparison, into = c("type", "diff")) %>% tidyr::pivot_wider(names_from = type, values_from = difference) %>% dplyr::mutate(rate = count/intensity) %>% dplyr::mutate(ba_group = paste(my_grouping, diff, sep = "_")): could not find function "%>%"
z <- find_changed_strategy(x, 2, "control", 2)
#> Error in region_df %>% dplyr::mutate(group = ifelse(group == comparison_group, "base", as.character(group))) %>% dplyr::group_by(my_grouping, batch, group) %>% dplyr::summarize(count = median(cells_perthousand_box_scaled, na.rm = T), intensity = median(intensity_box_scaled, na.rm = T)) %>% tidyr::pivot_wider(id_cols = c(my_grouping, batch), names_from = group, values_from = c(count, intensity)) %>% dplyr::mutate(dplyr::across(dplyr::starts_with("count_"), ~{ .x - count_base }), dplyr::across(dplyr::starts_with("intensity_"), ~{ .x - intensity_base})) %>% dplyr::select(-c(count_base, intensity_base)) %>% dplyr::select(my_grouping, batch, starts_with("count_"), starts_with("intensity_")) %>% tidyr::pivot_longer(cols = -c(my_grouping, batch), names_to = "comparison", values_to = "difference") %>% tidyr::separate(comparison, into = c("type", "diff")) %>% tidyr::pivot_wider(names_from = type, values_from = difference) %>% dplyr::mutate(rate = count/intensity) %>% dplyr::mutate(ba_group = paste(my_grouping, diff, sep = "_")): could not find function "%>%"