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
)
A data frame of the features (data.frame)
A vector of the treatment indicator (1/0 coded) (integer)
A vector of the outcome values (numeric)
A vector of the indices (integer)
The number of steps to take (integer)
The value between steps of K and the initial K value (integer)
A list of the KNN index matrices provided by the knn_index_mat function (list)
A vector of the propensity scores (defaults to RCT setting) (numeric)
A vector of the bootstrapped keys (default to NULL for no bootstrap case) (integer)
A list containing the optimal K value (list)