HTT
library(HTT)
data("Boston", package = "MASS")
head(Boston)
## crim zn indus chas nox rm age dis rad tax ptratio black lstat
## 1 0.00632 18 2.31 0 0.538 6.575 65.2 4.0900 1 296 15.3 396.90 4.98
## 2 0.02731 0 7.07 0 0.469 6.421 78.9 4.9671 2 242 17.8 396.90 9.14
## 3 0.02729 0 7.07 0 0.469 7.185 61.1 4.9671 2 242 17.8 392.83 4.03
## 4 0.03237 0 2.18 0 0.458 6.998 45.8 6.0622 3 222 18.7 394.63 2.94
## 5 0.06905 0 2.18 0 0.458 7.147 54.2 6.0622 3 222 18.7 396.90 5.33
## 6 0.02985 0 2.18 0 0.458 6.430 58.7 6.0622 3 222 18.7 394.12 5.21
## medv
## 1 24.0
## 2 21.6
## 3 34.7
## 4 33.4
## 5 36.2
## 6 28.7
# set the p-value of the permutation test to 0.01
htt_boston <- HTT(medv ~ . , data = Boston, controls = htt_control(pt = 0.01))
htt_boston
## Hypothesis Testing Tree
##
## node, split, n, pvalue
## * denotes terminal node
##
## [1] root (n = 506, pvalue = 0)
## | [2] rm<=7.437 (n = 476, pvalue = 0)
## | | [4] lstat<=15 (n = 314, pvalue = 0)
## | | | [6] rm<=6.797 (n = 256, pvalue = 0)
## | | | | [8] lstat<=4.615 (n = 10) *
## | | | | [9] lstat>4.615 (n = 246, pvalue = 0)
## | | | | | [12] rm<=6.543 (n = 212, pvalue = 0)
## | | | | | | [14] lstat<=7.57 (n = 42) *
## | | | | | | [15] lstat>7.57 (n = 170) *
## | | | | | [13] rm>6.543 (n = 34) *
## | | | [7] rm>6.797 (n = 58) *
## | | [5] lstat>15 (n = 162, pvalue = 0)
## | | | [10] crim<=0.65402 (n = 46) *
## | | | [11] crim>0.65402 (n = 116, pvalue = 0)
## | | | | [16] crim<=11.36915 (n = 77) *
## | | | | [17] crim>11.36915 (n = 39) *
## | [3] rm>7.437 (n = 30) *
## node parent leftChild rightChild statistic pval split var isleaf n
## 1 1 0 2 3 2258.92680 0.00 7.437 rm 0 506
## 2 2 1 4 5 1126.14057 0.00 15 lstat 0 476
## 3 3 1 NA NA 54.73540 NA <leaf> ptratio 1 30
## 4 4 2 6 7 750.08329 0.00 6.797 rm 0 314
## 5 5 2 10 11 201.23810 0.00 0.65402 crim 0 162
## 6 6 4 8 9 284.52923 0.00 4.615 lstat 0 256
## 7 7 4 NA NA 54.33706 NA <leaf> lstat 1 58
## 8 8 6 NA NA 0.00000 NA <leaf> <NA> 1 10
## 9 9 6 12 13 188.93990 0.00 6.543 rm 0 246
## 10 10 5 NA NA 73.70296 NA <leaf> dis 1 46
## 11 11 5 16 17 115.47482 0.00 11.36915 crim 0 116
## 12 12 9 14 15 126.15810 0.00 7.57 lstat 0 212
## 13 13 9 NA NA 20.83679 NA <leaf> nox 1 34
## 14 14 12 NA NA 12.63760 NA <leaf> dis 1 42
## 15 15 12 NA NA 66.02809 NA <leaf> crim 1 170
## 16 16 11 NA NA 32.28858 NA <leaf> lstat 1 77
## 17 17 11 NA NA 76.00906 0.02 <leaf> nox 1 39
## yval
## 1 22.53281
## 2 21.11071
## 3 45.09667
## 4 24.45924
## 5 14.62037
## 6 22.73242
## 7 32.08103
## 8 33.13000
## 9 22.30976
## 10 18.32826
## 11 13.15000
## 12 21.68821
## 13 26.18529
## 14 23.95000
## 15 21.12941
## 16 14.35195
## 17 10.77692

htt_iris <- HTT(Species ~., data = iris, controls = htt_control(pt = 0.01))
plot(htt_iris, layout = "tree")

ggrain
### https://cran.r-project.org/web/packages/ggrain/vignettes/ggrain.html
library(ggrain)
ggplot(iris, aes(1, Sepal.Width, fill = Species)) +
geom_rain(alpha = .5) +
theme_classic() +
scale_fill_brewer(palette = 'Dark2')

ggplot(iris, aes(1, Sepal.Width, fill = Species, color = Species)) +
geom_rain(alpha = .6,
boxplot.args = list(color = "black", outlier.shape = NA)) +
theme_classic() +
scale_fill_brewer(palette = 'Dark2') +
scale_color_brewer(palette = 'Dark2')
