This function calculates the difference between outcomes of a set of subjects and the subjects in their matched sets. That is, the value of Rj - Ri in equation (7) in Section 2.2 of the manuscript.

diff_reward(data_MS, idx_MS, max_size = 1, delta, dist_mat)

Arguments

data_MS

a matrix that contains outcome, treatment, and feature information of a set of subjects.

idx_MS

a data frame of two columns ID and index. ID records the IDs of subjects in data_MS. index records the column indices of these subjects in dist_mat.

max_size

an integer indicating the upper limit of the sizes of all matched sets. The default setting is max_size=1 which means finding the nearest neighbors of subjects.

delta

a scalar, as defined in equation (6) in Section 2.2 of the manuscript, indicating the upper limit of distances between a subject and the subjects in its matched set.
In future versions, we will extend this argument to a vector which means the upper limit can vary with subjects.

dist_mat

a precalculated matrix of distances between subjects. This matrix must include all subjects in data_MS.

Value

A vector of length max_size*nrow(data_MS). The (i-1)*max_size+1 to the i*max_size elements are the distances, in ascending order, between the ith subject and the subjects in its matched set. If the size of this matched set is smaller than max_size, some elements will be NA.