Finds the optimal K by choosing a grid of possible K values and finding the K values that has the smallest RMSE to the Transformed Outcome. We can also Bootstrap the procedure to find a more robust optimal K value.

knn_optimal_k(
  DF,
  W,
  Y,
  key,
  N_step,
  K_step,
  knn_index_list,
  propensity = mean(W),
  bootstrap_keys = NULL
)

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)

Value

A list containing the optimal K value (list)