R/knn_optimal_k.R
knn_optimal_k_separate.Rd
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
)
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)
The value of number of threads to use (integer)
A list containing the optimal K values (list)
We can also bootstrap the procedure to find a more robust optimal K value.