Generates a data.frame of binned values, binning starts at the first stimulus, e.g. 0 ms, and ends at
window_size
.
Usage
create_histogram_df(
df,
time_of_stim,
condition_names,
bin_size = 1,
window_size,
first_bin_on_stim = FALSE,
one_event_per_bin = FALSE
)
Arguments
- df
Data Frame or Tibble with the following columns:
time_ms
sweep
condition
stimulus
event_index
- time_of_stim
List, with event times in milliseconds.
- condition_names
Character, vector with condition titles.
- bin_size
Integer, histogram bin width size in milliseconds. Default is '1'.
- window_size
Integer, in milliseconds the size of the window to use for the histogram, the start of the window will be at the first stimulus.
- first_bin_on_stim
Logical, if
TRUE
the first bin center will occur on the first stimulus, i.e. 0. Default isFALSE
.- one_event_per_bin
Logical, if
TRUE
only a single event will be counted for each bin. Default isFALSE
.
Value
Tibble with the following columns:
condition
- charactercount_events
- integercount_sweeps
- integerh_counts
- nested list of integersh_density
- nested list of doublesh_bin_centers
- nested list of doublesprobability
- nested list of doublesh_count_norm_max
- nested list of doublesh_prob_norm_max
- nested list of doubles
Note
This only returns a tibble. Histogram related columns are nested, which facilitates
aggregating the output into a tibble for future comparison across experiments. See code example
using dplyr::select
and tidyr::unnest
for working with this functions output.
See also
analysis_evoked_ap()
for a workflow example that aggregates this functions output.
Examples
library(magrittr, include.only = "%>%")
simple_df <- data.frame(
time_ms = rep(c(417, 427), 10),
sweep = rep(c(1:10), each = 2),
condition = rep("control", 10),
stimulus = rep(c(1, 2), 10),
event_index = 1
)
df_output <-
create_histogram_df(
df = simple_df,
time_of_stim = c(415.5, 425.5),
condition_names = c("control", "drug1"),
bin_size = 1,
window_size = 20,
first_bin_on_stim = FALSE,
one_event_per_bin = FALSE
)
df_output %>%
dplyr::select(
condition, h_counts, h_density, h_bin_centers, probability, h_count_norm_max, h_prob_norm_max
) %>%
tidyr::unnest(c(
h_counts, h_density, h_bin_centers, probability, h_count_norm_max, h_prob_norm_max
))
#> # A tibble: 20 × 7
#> # Groups: condition [1]
#> condition h_counts h_density h_bin_centers probability h_count_norm_max
#> <chr> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 control 0 0 0.5 0 0
#> 2 control 10 0.5 1.5 1 1
#> 3 control 0 0 2.5 0 0
#> 4 control 0 0 3.5 0 0
#> 5 control 0 0 4.5 0 0
#> 6 control 0 0 5.5 0 0
#> 7 control 0 0 6.5 0 0
#> 8 control 0 0 7.5 0 0
#> 9 control 0 0 8.5 0 0
#> 10 control 0 0 9.5 0 0
#> 11 control 0 0 10.5 0 0
#> 12 control 10 0.5 11.5 1 1
#> 13 control 0 0 12.5 0 0
#> 14 control 0 0 13.5 0 0
#> 15 control 0 0 14.5 0 0
#> 16 control 0 0 15.5 0 0
#> 17 control 0 0 16.5 0 0
#> 18 control 0 0 17.5 0 0
#> 19 control 0 0 18.5 0 0
#> 20 control 0 0 19.5 0 0
#> # ℹ 1 more variable: h_prob_norm_max <dbl>