Converts an IRW-compliant dataset from long format to wide format while handling optional metadata elements, filtering by wave, and ensuring consistency.
Usage
irw_long2resp(
df,
wave = NULL,
id_density_threshold = 0.1,
agg_method = "mean",
check_resp = FALSE
)Arguments
- df
A data frame containing IRW-compliant item response data in long format.
- wave
(Optional) A numeric value specifying which wave to filter. If the dataset does not have a
wavecolumn, this input is ignored. Defaults to the most frequent wave ifNULL.- id_density_threshold
A numeric value between
0.0and1.0specifying the minimum response density required for anidto be included. Default is0.1. Set toNULLto disable filtering.- agg_method
A string specifying how to handle multiple
id-itempairs. Options:"mean"(default),"mode","median","first".- check_resp
Logical; if
TRUE, perform basic response diagnostics on items using default thresholds and attach results as an attribute. Default isFALSE.
Value
A data frame in wide format where rows represent id values and columns
represent item_* responses.
If check_resp = TRUE, an attribute "resp_checks" is attached:
single_category_items: character vector of item IDs with only one observed category.sparse_category_items: named list; each element is a data.frame with sparse categories for that item (columns:resp,count,prop).
Details
This function applies a default sparsity filter with a threshold of 0.1 for id density
to avoid excessive sparsity in the response matrix.
Users can disable filtering by setting id_density_threshold = NULL.
If check_resp = TRUE, the function will run a basic response diagnostic using
default thresholds (min_count = 5, min_prop = 0.01), attach the results as
an attribute "resp_checks" on the returned object, and add a short NOTE with
counts of flagged items. A response category is considered sparse if it has fewer than
min_count responses OR a within-item proportion smaller than min_prop.
For more control, use irw_check_resp() directly.