Finds the optimal K separately for treated and untreated nearest neighbors by choosing a grid of possible K values and finding the K values that has the smallest RMSE to the Transformed Outcome. The combination of the optimal K value for the treated and the untreated that yields the smallest transformed error loss will be returned.

knn_optimal_k_separate(
  DF,
  W,
  Y,
  key,
  N_step,
  K_step,
  knn_index_list,
  propensity = mean(W),
  bootstrap_keys = NULL,
  threads = 1L
)

Arguments

DF

A data frame of the features (data.frame)

W

A vector of the treatment indicator (1/0 coded) (integer)

Y

A vector of the outcome values (numeric)

key

A vector of the indices (integer)

N_step

The number of steps to take (integer)

K_step

The value between steps of K and the initial K value (integer)

knn_index_list

A list of the KNN index matrices provided by the knn_index_mat function (list)

propensity

A vector of the propensity scores (defaults to RCT setting) (numeric)

bootstrap_keys

A vector of the bootstrapped keys (default to NULL for no bootstrap case) (integer)

threads

The value of number of threads to use (integer)

Value

A list containing the optimal K values (list)

Details

We can also bootstrap the procedure to find a more robust optimal K value.