# f_table()

## Introduction

After getting a vector of response events sorted by bins from a raw time vector, it is often necessary to create frequency tables in order to analyze the response distribution for a given experimental trial or session. Here we introduce a function to do so. The function takes a vector of ‘binarized’ responses as input and outputs a data frame with 3 columns:

- `bins` which is the bin index for every data point.
- `freq` the frequency of each bin.
- `prop` the frequency expressed as a proportion of the total responses.

The `f_table()` takes the following parameters:

- `x` the numeric vector of binned time data.
- `min_x` the minimum value of the binned distribution.
- `max_x` the maximum value of the binned distribution.
- `bin_res` the bin resolution for

This function includes zero-frequency bins in the given interval.

## Example

First let’s load a data sample of response times:

    data("r_times")

    r_times

    ##   [1]  28.1  40.7  44.2  44.4  44.7  45.0  45.4  47.9  48.1  48.3  48.6  48.8
    ##  [13]  49.8  50.2  50.7  51.2  51.4  51.7  51.9  52.7  53.0  53.5  53.7  53.9
    ##  [25]  54.1  54.3  54.9  55.3  55.5  55.7  55.8  57.2  57.4  57.7  58.3  58.5
    ##  [37]  58.7  60.4  60.6  60.7  61.1  61.6  61.8  62.6  62.8  63.1  63.3  63.5
    ##  [49]  63.8  64.4  64.8  64.9  65.1  66.1  66.4  67.0  68.7  68.9  69.5  69.6
    ##  [61]  70.1  70.9  71.0  71.3  71.6  71.8  73.9  74.1  74.4  74.6  75.2  76.4
    ##  [73]  76.6  77.4  77.6  77.8  78.2  79.3  79.9  80.5  80.7  81.3  82.2  82.4
    ##  [85]  82.6  82.9  83.0  83.1  83.7  84.4  84.4  84.8  85.0  85.6  86.6  87.0
    ##  [97]  87.1  87.3  87.4  87.8  88.1  88.2  89.4  99.1  99.3  99.6  99.8 100.2
    ## [109] 133.1 133.1 133.6 134.9 135.2 135.3 135.4 135.7 136.5 173.8 174.1 174.3
    ## [121] 174.7 175.9 176.3 176.6 177.4 177.5 177.7 178.1 178.2 178.4 178.5 178.8
    ## [133] 179.4

Now we will use the `get_bins()` function included in this package (see `get_bins.Rmd` for further details) to convert the raw data points into time bins and then create the frequency table with `f_table`:

    bin_res <- 10 # Lower values will create a higher resolution distribution and vice-versa.
    min_x <- 0 # We use 0 as a starting point in order to get a distribution for the complete duration of the trail.
    max_x <- 180 # In this specific example the total trail duration was 3 minutes.
    binarized_data <- get_bins(r_times, min_x, max_x, bin_res)
    data_ftable <- f_table(binarized_data, min_x, max_x, bin_res)

    data_ftable

    ##    bins freq        prop
    ## 1     0    0 0.000000000
    ## 2    10    0 0.000000000
    ## 3    20    0 0.000000000
    ## 4    30    1 0.007518797
    ## 5    40    0 0.000000000
    ## 6    50   12 0.090225564
    ## 7    60   24 0.180451128
    ## 8    70   23 0.172932331
    ## 9    80   19 0.142857143
    ## 10   90   24 0.180451128
    ## 11  100    4 0.030075188
    ## 12  110    1 0.007518797
    ## 13  120    0 0.000000000
    ## 14  130    0 0.000000000
    ## 15  140    9 0.067669173
    ## 16  150    0 0.000000000
    ## 17  160    0 0.000000000
    ## 18  170    0 0.000000000
    ## 19  180   16 0.120300752

Finally let’s plot the data to visualize the resulting structure: