Learn R Programming

eventreport (version 0.1.1)

mean_range: Calculate the mean within-event range across event reports for numeric variables

Description

This function calculates the mean range for one or more numeric variables grouped by an event identifier. It is useful for diagnosing aggregation sensitivity by assessing how much spread exists in numeric values reported across event reports concerning the same event.

Usage

mean_range(data, group_var, variables)

Value

A tibble with two columns:

variable

The name of each variable.

mean_range

The mean range across events for that variable.

Arguments

data

A data frame containing event report level data.

group_var

A character string naming the column that uniquely identifies events (e.g., "event_id").

variables

A character vector of column names to compute ranges for. All specified variables must be numeric.

Details

For each variable and event, the function computes the range (i.e., the difference between the maximum and minimum) of values reported across event reports. These values are then averaged across all events to produce a single score per variable. The result is a long-format dataframe that shows which numeric variables exhibit the widest event report level disagreement.

Examples

Run this code
df <- data.frame(
  event_id = c(1, 1, 2, 2, 3),
  deaths_best = c(10, 20, 5, 15, 10)
)
mean_range(
  df,
  group_var = "event_id",
  variables = c("deaths_best")
)

Run the code above in your browser using DataLab