R package for Frequency Profiles
The frequency profile is a method for visualizing an individuals' behaviors in real time or post-hoc. This package provides tools for converting occurrence/nonoccurrence (binary) behavioral data into a frequency profile format, tools for plotting the frequency profile, and an interface for exploring frequency profiles.
Data for the above graph can be found in data
and data-raw
and originates from:
Ordonez, F.J., de Toledo, P., Sanchis, A. (2013). Activity Recognition Using Hybrid Generative/Discriminative Models on Home Environments Using Binary Sensors. Sensors, 13, 5460-5477.
- Frequency profiles can be adjusted by setting three parameters: window size, step size, and resolution.
- Window size is a critically important parameter, and its optimal value will depend both on the application and the nature of the behaviors being observed. Generally speaking, small window sizes are preferable when behavior changes frequently or when behavior occurs in short bursts, and large window sizes are preferable when behavior changes infrequently. When scanning through an archive of behavioral data, one might increase the window size when behavior changes are infrequent and then decrease it when such changes are frequent or when one is searching for a brief behavioral event.
- Generally, one should also use a step size of 1; information loss is substantial with larger step sizes.
- Generally speaking, the resolution would be set to 1, which means that one is graphing the smallest possible time interval one has recorded. This is especially important when one is observing behaviors that occur at a high frequency or when transitions from one behavior to another occur at a high frequency. With low frequency behaviors, one would presumably lose little information by reducing resolution (that is, by collapsing one’s data into larger bins).
# Install CRAN version:
install.packages("FreqProf")
# Or install Github (more recent, less stable, more fun) version:
devtools::install_github("gitronald/FreqProf")
# Load the package and data
library(FreqProf)
data(s58)
- This package includes a user-friendly interface - using the "Shiny App" framework - allowing people with no prior R programming experience to input their data, utilize the visualization tools, explore the effects of manipulating the parameters, and download publication quality plots.
> runEx()
- Converts binary data to a list with information needed to create a frequency profile
> freqprof(s58, window= round(0.25 * nrow(s58)), step = 1, resolution = 1, which= "sum")
$window
[1] 773
$step
[1] 1
$resolution
[1] 1
$raw.data
V1 V2 V3 V4
1 1 0 0 0
2 0 0 0 0
3 0 0 0 0
4 0 0 0 0
5 0 0 0 0
6 0 0 0 0
$type
[1] "sum"
$data
time panels V1 V2 V3 V4
1 0 1 0 0 0 0
2 1 1 1 0 0 0
3 2 1 1 0 0 0
4 3 1 1 0 0 0
5 4 1 1 0 0 0
6 5 1 1 0 0 0
- Use plot_freqprof to plot frequency profile data generated from freqprof
- Arguments: data.freqprof- data created by freqprof function yAxis- a string labeling the y axis xAxisUnits- a string indicating x-axis units, defaults to "sec" panel.in-if FALSE the first panel of the frequency profile, the window moving in, is not plotted panel.out- if FALSE the third panel of the frequency profile, the window backing out, is not plotted gg- if TRUE, will use ggplot2 package to plot frequency profiles multiPlot- if TRUE will plot each behavior in its own panel tick.every- spacing between plot tick marks.By default, N/30, where N is the number of time units label.every- label every X ticks, where X = label.every. By default, label.every = 3
> plot_freqprof(FPdata, gg = FALSE, multiPlot = FALSE)
- K-S test for multiple variables (of the same name) in separate data.frames
> ks.testm(s58, s59, v)
vars D P
1 V1 0 1
2 V2 0 1
3 V3 0 1
4 V4 0 1
- Correlation test for multiple variables (of the same name) in separate data.frames
> cor.testm(s58, s59, method= "pearson")
var cor ci.min ci.max p stat df alt method
1 V1 1 1 1 0 Inf 3090 two.sided pearson
2 V2 1 1 1 0 Inf 3090 two.sided pearson
3 V3 1 1 1 0 2637813758 3090 two.sided pearson
4 V4 1 1 1 0 Inf 3090 two.sided pearson
import_data()
- Interactive method for importing a csv, bin, or fpw file as a data.frameread.bin
- Import a bin file to a data.frameread.fpw
- Import a fpw file to a data.frame
generate_dates
- Generate a sequence of dates
Copyright American Institute for Behavioral Research and Technology (http://aibrt.org/).