Open matiasandina opened 1 year ago
In the past, this function was split in two. One that adds the stage, and one that counts. It is somewhat related to #11, which needs to add stages using start_dt
and end_dt
for treatments. In the case of #11, it's because of alignment, but a general purpose function that adds labels to the data might be a good idea. It's tough to handle the unique cases without asking a lot from the user (properly and manually defining each start_dt
and end_dt
for the data to be assigned to epoch by id
).
add_epoc <- function(joint_pellet_data, experiment_epocs){
joint_pellet_data %>%
mutate(
epoc = case_when(
data.table::between(tdt_datetime,
exp_start,
experiment_epocs["opto_start"]) ~ "pre",
data.table::between(tdt_datetime,
experiment_epocs["opto_start"],
experiment_epocs["opto_stop"]) ~ "stim",
data.table::between(tdt_datetime,
experiment_epocs["opto_stop"],
exp_stop) ~ "post",
TRUE ~ "hab"),
epoc = factor(epoc, levels=c("pre", "stim", "post")))
}
summarise_by_epoc <- function(df){
df %>%
group_by(epoc, .drop=F) %>%
count()
}
When doing experiments. We often want to count fast the number of events to do the classic pre-stim-post plot.
Here's a preliminary idea of how to do that
A nice property is that it can handle empty data frames like this