Skip to content

Commit ab0057e

Browse files
authored
report significance of interaction detection results (#96)
See #95 for more details, now also report significance of interaction detection results in `gozh` and `gozh_detector`.
2 parents ab9ce74 + bece48d commit ab0057e

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# gdverse 1.6
22

3-
- Improve robustness of non-centrality parameter estimation for q-statistic confidence intervals (#93).
3+
* Report significance of interaction detection results in geographical detector (#95).
4+
5+
* Improve robustness of non-centrality parameter estimation for q-statistic confidence intervals (#93).
46

57
# gdverse 1.5.1
68

R/gozh.R

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ gozh_detector = \(formula, data, cores = 1,
164164
}
165165
calcul_pd = \(xvar,...){
166166
discdf = gdverse::rpart_disc(paste0(yname,'~',paste(xvar,collapse = '+')),data = dti,...)
167-
qv = gdverse::factor_detector(dti[,yname,drop = TRUE],discdf)[[1]]
168-
return(qv)
167+
qv = gdverse::factor_detector(dti[,yname,drop = TRUE],discdf)
168+
return(unlist(qv))
169169
}
170170
interact_type = \(qv1,qv2,qv12){
171171
if (qv12 < min(qv1, qv2)) {
@@ -198,21 +198,26 @@ gozh_detector = \(formula, data, cores = 1,
198198
variable1 = purrr::map_chr(seq_along(xinteract), \(x) xinteract[[x]][1])
199199
variable2 = purrr::map_chr(seq_along(xinteract), \(x) xinteract[[x]][2])
200200
if (doclust) {
201-
qv12 = as.numeric(parallel::parLapply(cl,xinteract,calcul_pd))
201+
qv12 = tibble::as_tibble(do.call(rbind,parallel::parLapply(cl,xinteract,calcul_pd)))
202202
} else {
203-
qv12 = purrr::map_dbl(xinteract,calcul_pd)
203+
qv12 = purrr::map_dfr(xinteract,calcul_pd)
204204
}
205205
res = gdverse::gd(paste0(yname,' ~ .'),data = newdata,type = "factor")[[1]]
206206
qv = res[,2,drop = TRUE]
207-
names(qv) = res[,1,drop = TRUE]
207+
pv = res[,3,drop = TRUE]
208+
names(qv) = names(pv) = res[,1,drop = TRUE]
208209
qv1 = qv[variable1]
209210
qv2 = qv[variable2]
211+
pv1 = pv[variable1]
212+
pv2 = pv[variable2]
210213
res = tibble::tibble(
211-
"Variable1 Q-statistics" = qv1,"Variable2 Q-statistics" = qv2,
212-
"Variable1 and Variable2 interact Q-statistics" = qv12,
214+
"Variable1 Q-statistics" = qv1, "Variable2 Q-statistics" = qv2,
215+
"Variable1 and Variable2 interact Q-statistics" = qv12[,1,drop = TRUE],
213216
"variable1" = variable1, "variable2" = variable2,
214-
"Interaction" = purrr::pmap_chr(list(qv1 = qv1,qv2 = qv2,qv12 = qv12),
215-
interact_type)) %>%
217+
"Interaction" = purrr::pmap_chr(list(qv1 = qv1,qv2 = qv2,qv12 = qv12[,1,drop = TRUE]),
218+
interact_type),
219+
"Variable1 P-value" = pv1, "Variable2 P-value" = pv2,
220+
"Variable1 and Variable2 interact P-value" = qv12[,2,drop = TRUE]) %>%
216221
dplyr::select(variable1,variable2,Interaction,
217222
dplyr::everything())
218223
res = list("interaction" = res)

0 commit comments

Comments
 (0)