response_rate: Calculate response rate

View source: R/response_rate.R

response_rateR Documentation

Calculate response rate

Description

Calculate response rate

Usage

response_rate(
  data,
  valid_col,
  participant_col,
  time_col = NULL,
  period_start = NULL,
  period_end = NULL
)

Arguments

data

data frame with data

valid_col

name of the column that stores whether the beep was answered or not

participant_col

name of the column that stores the participant id (or equivalent)

time_col

optional: name of the column that stores the time of the beep, as a 'POSIXct' object.

period_start

string representing the starting date to calculate response rates (optional). Accepts dates in the following formats: yyyy-mm-dd oryyyy/mm/dd.

period_end

period end to calculate response rates (optional).

Value

a data frame with the response rate for each participant, and the number of beeps used to calculate the response rate

Examples

# Example 1: calculate response rates for the whole study
# Get example data
data(example_data)

# Calculate response rate for each participant

# We don't specify time_col, period_start or period_end.
# Response rates will be based on all the participant's data
response_rate <- response_rate(data = example_data,
                               valid_col = answered,
                               participant_col = participant)

# Example 2: calculate response rates for a specific time period
data(example_data)

# Calculate response rate for each participant between dates
response_rate <- response_rate(data = example_data,
                               valid_col = answered,
                               participant_col = participant,
                               time_col = sent,
                               period_start = '2024-05-15',
                               period_end = '2024-05-31')

# Get participants with a response rate below 0.5
response_rate[response_rate$response_rate < 0.5,]


mpathr documentation built on June 8, 2025, 11:08 a.m.