This function identifies the best Variable of Interest (VOI) based on the minimum or maximum value of a specified column. It groups the data by a specified column and selects rows with the minimum or maximum value in another specified column.
A data frame containing the dataset.
A symbol specifying the column name to group by. Defaults to the first column of the data.
A symbol specifying the column name to use for selecting the minimum or maximum value. Defaults to the second column of the data.
A vector of column names to select in the final output. Defaults to all columns.
A character string specifying whether to select the "min" or "max" value. Defaults to "min".
A data frame with the best VOIs based on the specified criteria.
data <- data.frame(cog = c('A', 'A', 'B', 'B'),
voi = c('X1', 'X2', 'Y1', 'Y2'),
d = c(0.5, 0.7, 0.3, 0.9),
p = c(0.01, 0.05, 0.02, 0.03),
multi = c(TRUE, FALSE, TRUE, FALSE))
identify_best_voi(data, group_var = cog, value_var = p,
select_vars = c("cog", "voi", "d", "p", "multi"), selection = "min")
#> # A tibble: 2 × 5
#> cog voi d p multi
#> <chr> <chr> <dbl> <dbl> <lgl>
#> 1 A X1 0.5 0.01 TRUE
#> 2 B Y1 0.3 0.02 TRUE