Learn R Programming

rankdifferencetest (version 2025.12.4)

srt_data: Get data for the signed-rank test.

Description

Gets data needed to compute signed-rank results. The returned list is designed to be reused by higher-level functions.

Usage

srt_data(x, ...)

# S3 method for numeric srt_data(x, y = NULL, x_name, y_name = NULL, ...)

# S3 method for data.frame srt_data(x, formula, agg_fun = "error", ...)

Value

list

Arguments

x

(numeric)
Numeric vector or data.frame of data. Values with non-finite values (infinite or missing) are silently dropped.

...

Unused additional arguments.

y

(numeric: NULL)
Numeric vector of data or NULL. If NULL (default), a one-sample test is performed using x. If numeric, differences are calculated as x - y. Pairs with non-finite values (infinite or missing) are silently dropped.

x_name

(Scalar character)
Name of x variable.

y_name

(Scalar character or NULL)
Name of y variable. If y = NULL then y_name = NULL.

formula

(formula)
A formula of form:

y ~ group | block

Use when data is in tall format. y is the numeric outcome, group is the binary grouping variable, and block is the subject/item-level variable indicating pairs of observations. group will be converted to a factor and the first level will be the reference value. For example, when levels(data$group) <- c("pre", "post"), the focal level is 'post', so differences are post - pre. Pairs with non-finite values (infinite or missing) are silently dropped. See agg_fun for handling duplicate cases of grouping/blocking combinations.

y ~ x

Use when data is in wide format. y and x must be numeric vectors. Differences are calculated as data$y - data$x. Pairs with non-finite values (infinite or missing) are silently dropped.

~ x

Use when data$x represents pre-calculated differences or for the one-sample case. Values with non-finite values (infinite or missing) are silently dropped.

agg_fun

(Scalar character or function: "error")
Used for aggregating duplicate cases of grouping/blocking combinations when data is in tall format and formula has structure y ~ group | block. "error" (default) will return an error if duplicate grouping/blocking combinations are encountered. Select one of "first", "last", "sum", "mean", "median", "min", or "max" for built in aggregation handling (each applies na.rm = TRUE). Or define your own function. For example, myfun <- function(x) {as.numeric(quantile(x, 0.75, na.rm = TRUE))}.