intervals
zhangxueyuan-alt opened this issue · 3 comments
The RGD code cannot modify intervals.
In version 1.0-2 and earlier versions of gdverse, the discnum
in rgd
can be set to a corresponding number of discretization categories for each variable, as shown in the example code below.
library(gdverse)
packageVersion("gdverse")
#> [1] '1.0.2'
data('sim')
rgd(y~xa+xb+xc,data = sim ,
discnum = c(3,4,5))
#> RGD Model
#> *** Factor Detector
#>
#> | variable | Q-statistic | P-value |
#> |:--------:|:-----------:|:-----------:|
#> | xc | 0.6900534 | 9.86000e-10 |
#> | xb | 0.5056807 | 1.08000e-09 |
#> | xa | 0.3579193 | 2.11993e-07 |
Created on 2024-09-24 with reprex v2.1.1
Is it what you want to express "perform different categories of discretization numbers for each variable that needs to be discretized in rgd
"?
Please download version 1.0-3
of gdverse
(which will be pushed to CRAN shortly), in this version, RGD
has made significant changes that can meet your needs. You can input a series of discnums, and all variables to be discretized will undergo the corresponding discretization process according to discnum
and calculate Q values. For example:
library(gdverse)
packageVersion("gdverse")
#> [1] '1.0.3'
data('sim')
g = rgd(y~xa+xb+xc,data = sim ,
discnum = c(3,4,5))
g
#> *** Robust Geographical Detector
#>
#> | variable | Q-statistic | P-value |
#> |:--------:|:-----------:|:------------:|
#> | xc | 0.6900534 | 9.860000e-10 |
#> | xb | 0.5627648 | 3.301300e-08 |
#> | xa | 0.4525275 | 1.257094e-05 |
#>
#> #### Only display the results corresponding to the maximum number of discretizations!
# the result of RGD model
g$factor
#> # A tibble: 9 × 4
#> variable `Q-statistic` `P-value` discnum
#> <chr> <dbl> <dbl> <dbl>
#> 1 xc 0.606 1.86e-10 3
#> 2 xb 0.473 1.53e- 9 3
#> 3 xa 0.358 2.12e- 7 3
#> 4 xc 0.637 2.38e-10 4
#> 5 xb 0.506 1.08e- 9 4
#> 6 xa 0.406 1.98e- 5 4
#> 7 xc 0.690 9.86e-10 5
#> 8 xb 0.563 3.30e- 8 5
#> 9 xa 0.453 1.26e- 5 5
# robust discrete results
g$disc
#> # A tibble: 240 × 4
#> xa xb xc discnum
#> <chr> <chr> <chr> <dbl>
#> 1 group1 group3 group2 3
#> 2 group3 group3 group3 3
#> 3 group2 group3 group2 3
#> 4 group2 group2 group2 3
#> 5 group3 group3 group3 3
#> 6 group2 group3 group3 3
#> 7 group3 group3 group3 3
#> 8 group2 group2 group2 3
#> 9 group3 group2 group3 3
#> 10 group3 group2 group3 3
#> # ℹ 230 more rows
Created on 2024-09-24 with reprex v2.1.1