The goal of package semidist
is to provide an easy way to implement the semi-distance methods (Zhong et al., 2023) and MV index methods (Cui, Li and Zhong, 2015; Cui and Zhong, 2019).
To install semidist
,
Here is a simple example showing how to use semidist
to measure the dependence between a categorical variable and a multivariate continuous variable, and apply the measure on testing the independence and conduct groupwise feature screening.
library(semidist)
X <- mtcars[, c("mpg", "disp", "drat", "wt")]
y <- factor(mtcars[, "am"])
sdcov(X, y)
#> [1] 31.78288
sdcor(X, y)
#> [1] 0.3489821
sd_test(X, y)
#>
#> Semi-Distance Independence Test (Permutation Test with K = 10000)
#>
#> Data: X and y, Sample size = 32
#> Test statistic = 940.344, p-value = 0.0005999
#> Alternative hypothesis: Two random variables are not independent
sd_sis(X, y, d = 2)
#> $group_info
#> $group_info$`Grp mpg`
#> [1] "mpg"
#>
#> $group_info$`Grp disp`
#> [1] "disp"
#>
#> $group_info$`Grp drat`
#> [1] "drat"
#>
#> $group_info$`Grp wt`
#> [1] "wt"
#>
#>
#> $measurement
#> Grp mpg Grp disp Grp drat Grp wt
#> 0.3447938 0.3488447 0.5054821 0.5358834
#>
#> $selected
#> [1] "wt" "drat"
#>
#> $ordering
#> [1] "Grp wt" "Grp drat" "Grp disp" "Grp mpg"
# Suppose we have prior information for the group structure as
# ("mpg", "drat"), ("disp", "hp") and ("wt", "qsec")
group_info <- list(
mpg_drat = c("mpg", "drat"),
disp_wt = c("disp", "wt")
)
sd_sis(X, y, group_info, d = 2)
#> $group_info
#> $group_info$mpg_drat
#> [1] "mpg" "drat"
#>
#> $group_info$disp_wt
#> [1] "disp" "wt"
#>
#>
#> $measurement
#> mpg_drat disp_wt
#> 0.3518051 0.3488598
#>
#> $selected
#> [1] "mpg" "drat"
#>
#> $ordering
#> [1] "mpg_drat" "disp_wt"