find_strongest_peaks {forceR}R Documentation

Find Peaks

Description

Identifies peaks in a first iteration and optimizes the starts and ends of the strongest peaks per species in a second iteration.

Usage

find_strongest_peaks(
  df,
  no.of.peaks = 5,
  initial.threshold = 0.05,
  slope.length.start = 5,
  slope.length.end = 5,
  slope.thresh.start = 0.02,
  slope.thresh.end = 0.02,
  path.data = NULL,
  path.plots = NULL,
  show.progress = FALSE
)

Arguments

df

A data frame or tibble in the below format. The columns t (= time), force and measurement (= measurement ID) must be present.

no.of.peaks

A numeric value defining how many peaks per species (not per measurement") should be identified. The function will always return the strongest peaks. Default: 5

initial.threshold

A numeric value defining the threshold (in % of the maximum force of the measurement) that is used during the first iteration. Default: 0.05

slope.length.start

A numeric value defining the window size (in time steps) of slope calculation for peak starts during the second iteration. Default: 5

slope.length.end

A numeric value defining the window size (in time steps) of slope calculation for peak ends during the second iteration. Default: 5

slope.thresh.start

A numeric value defining the threshold at which to stop the sliding window and save the current time point as the actual start of the current peak. Default: 0.04

slope.thresh.end

A numeric value defining the threshold at which to stop the sliding window and save the current time point as the actual end of the current peak. Default: 0.04

path.data

A string character defining where to save the results. If NULL (default), data is not stored in a file. Default: NULL.

path.plots

A string character defining where to save the plots. Default: NULL.

show.progress

A logical value indicating if progress should be printed to the console. Default: FALSE.

Details

The input data frame df needs to contain the following columns:

t force measurement
t.1 force.1 measurement.1
... ... ...
t.n force.n measurement.m

Value

Creates a tibble in the following format and saves it as a CSV-file: The column species contains one species per row
(⁠species.1 ... species.n⁠).

The column measurements contains as many measurements as no.of.peaks, separated by '⁠;⁠':
(⁠measurement.1; ...; measurements.no.of.peaks⁠).

The column starts contains as many peak starts as no.of.peaks, separated by '⁠;⁠':
(⁠start.1; ...; start.no.of.peaks⁠).

The column ends contains as many peak ends as no.of.peaks, separated by '⁠;⁠':
(⁠end.1; ...; end.no.of.peaks⁠).

Examples

require(dplyr)
# Using the forceR::df.all.200.tax dataset:

# reduce dataset (only rows 40 to 95 of species A (containing data of
  # measurement 1 and 2 (m_01 and m_02)))
df.all.200.tax_filtered <- forceR::df.all.200.tax[40:95, ] %>%
  filter(species == "species_A")

# find the 4 strongest peaks
peaks.df <- find_strongest_peaks(df = df.all.200.tax_filtered,
                                 no.of.peaks = 4)

# plot results (three peaks in measurement 1, 1 peak in measurement 2):
# plot_peaks(df.peaks = peaks.df,
#            df.data = df.all.200.tax_filtered,
#            additional.msecs = 20)


[Package forceR version 1.0.20 Index]