Skip to content

Commit 6776366

Browse files
author
livio
committed
...
1 parent ecf28b3 commit 6776366

22 files changed

+350
-196
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(^\.github/.+$)|(^README.+$)

DESCRIPTION

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
Package: jointest
2-
Version: 1.2.0
3-
Date: 2022-09-15
4-
Title: Multivariate testing trought joint sign-flip scores [Hemerik, Goeman and Finos (2020)].
5-
Author: Livio Finos
6-
Maintainer: Livio Finos <livio.finos@unipd.it>
7-
Description: runs resampling-based tests jointly (e.i. sign-flip score tests [Hemerik, Goeman and Finos (2020)] to allow for multivariate testing -- e.g. weak and strong control of the Familywise Error Rate or True Discovery Proportion.
8-
Imports: flipscores, methods
9-
Encoding: UTF-8
10-
License: GPL-2
11-
RoxygenNote: 7.1.2
1+
Package: jointest
2+
Version: 1.2.0
3+
Date: 2022-09-15
4+
Title: Multivariate testing trought joint sign-flip scores [Hemerik, Goeman and Finos (2020)].
5+
Author: Livio Finos
6+
Maintainer: Livio Finos <livio.finos@unipd.it>
7+
Description: runs resampling-based tests jointly (e.i. sign-flip score tests [Hemerik, Goeman and Finos (2020)] to allow for multivariate testing -- e.g. weak and strong control of the Familywise Error Rate or True Discovery Proportion.
8+
Imports: flipscores, ggplot2, methods, flip
9+
Encoding: UTF-8
10+
License: GPL-2
11+
RoxygenNote: 7.2.3

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ export(join_flipscores)
77
export(p.adjust.fwer)
88
import(flipscores)
99
import(ggplot2)
10+
importFrom(flip,flip.adjust)
11+
importFrom(stats,median)
12+
importFrom(stats,qnorm)
13+
importFrom(stats,quantile)
14+
importFrom(stats,update)

R/combine.R

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#' (nonparametric) combination of jointest object
2-
#' @param combined a) NULL = combines all coeffs with the same names along models,
3-
#' b) a vector of characters = it gives a combination for each stats with these names
4-
#' c) a list of arrays = each array has two columns reporting model (first column)
2+
#' @param mods object of class \code{jointest} (it can be a list of glm or flipscores converted in a \code{jointest} object using \code{as.jointest})
3+
#' @param comb_funct Combining function to be used. Several functions are implemented: "mean", "median", "Fisher", "Liptak", (equal to) "Stoufer", "Tippet", (equal to) "minp", "maxT" (the default).
4+
#' Alternativelly it can be a custom function that has a matrix as input. The function return a vector of length equal to the number of rows of the input matrix.
5+
#' @param combined a) if \code{NULL} it combines all coefficients with the same names along models,
6+
#' b) if a vector of characters, it gives a combination for each stats with these names
7+
#' c) if a list of arrays, each array has two columns reporting model (first column)
58
#' and name of the coefficient to be combined.
9+
#' @param tail direction of the alternative hypothesis. It can be "two.sided" (or 0, the default), "less" (or -1) or "greater" (or +1)
610
#' @export
11+
#'
712
combine <- function (mods, comb_funct = "maxT", combined = NULL, tail = 0)
813
{
914
names(mods) = .set_mods_names(mods)
@@ -29,10 +34,10 @@ combine <- function (mods, comb_funct = "maxT", combined = NULL, tail = 0)
2934
uniq_nm = unique(unlist(combined))
3035
}
3136
Tspace = .get_all_Tspace(mods)
32-
res = lapply(1:length(combined), jointest:::.npc2jointest,
37+
res = lapply(1:length(combined), .npc2jointest,
3338
Tspace = Tspace, combined = combined, tail = tail, comb_funct = comb_funct)
3439
names(res) = names(combined)
35-
class(res) <- c("jointest", class(res))
40+
class(res) <- unique(c("jointest", class(res)))
3641
res
3742
}
3843

@@ -41,7 +46,7 @@ combine <- function (mods, comb_funct = "maxT", combined = NULL, tail = 0)
4146
comb_name = names(combined)[id]
4247
if (is.null(comb_name))
4348
comb_name = "Combined"
44-
Tspace = jointest:::npc(Tspace[, combined[[id]]], comb_funct = comb_funct,
49+
Tspace = npc(Tspace[, combined[[id]]], comb_funct = comb_funct,
4550
tail = tail)
4651
colnames(Tspace) = comb_name
4752
summary_table = data.frame(Coeff = comb_name, Stat = comb_funct,

R/facilities.R

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,39 +45,39 @@ make_models<-function (mod, max_cat = 3, var_exclude = NULL, data_new = NULL,
4545
}
4646

4747
#########################
48-
multiverse_boostrap<-function (mods, data, var_interest, B = 500, verbatim = TRUE)
49-
{
50-
n_data <- dim(data)[1]
51-
yvar <- all.vars(formula(mods[[1]]))[1]
52-
vars <- all.vars(formula(mods[[1]]))[-1]
53-
nvar <- length(vars)
54-
num_comb <- length(mods)
55-
pboot <- matrix(NA, B, num_comb)
56-
eboot <- matrix(NA, B, num_comb)
57-
pval <- rep(NA, num_comb)
58-
eval <- rep(NA, num_comb)
59-
pos <- which(vars == var_interest)
60-
for (k in 1:num_comb) {
61-
formula <- formula(mods[[k]])
62-
m1 <- mods[[k]]
63-
pval[k] <- coef(summary(m1))[pos + 1, 4]
64-
eval[k] <- coef(m1)[pos + 1]
65-
data$ytemp <- data[, yvar] - coef(m1)[pos + 1] * (data[,
66-
var_interest])
67-
temp <- "ytemp ~ "
68-
for (j in 1:nvar) temp <- paste(temp, paste("+",
69-
all.vars(formula(mods[[k]]))[-1][j]))
70-
formulak <- formula(temp)
71-
set.seed(1)
72-
bt <- boot::boot(data, function(d, i) coef(summary(update(mods[[k]],
73-
data = d[i, ], formula = formulak)))[pos + 1, c(1,
74-
4)], R = B, stype = "i")
75-
eboot[, k] <- bt$t[, 1]
76-
pboot[, k] <- bt$t[, 2]
77-
if (verbatim)
78-
show(paste("model", k))
79-
}
80-
list(pval = pval, eval = eval, pboot = pboot, eboot = eboot,
81-
models = mods)
82-
}
83-
48+
# multiverse_boostrap<-function (mods, data, var_interest, B = 500, verbatim = TRUE)
49+
# {
50+
# n_data <- dim(data)[1]
51+
# yvar <- all.vars(formula(mods[[1]]))[1]
52+
# vars <- all.vars(formula(mods[[1]]))[-1]
53+
# nvar <- length(vars)
54+
# num_comb <- length(mods)
55+
# pboot <- matrix(NA, B, num_comb)
56+
# eboot <- matrix(NA, B, num_comb)
57+
# pval <- rep(NA, num_comb)
58+
# eval <- rep(NA, num_comb)
59+
# pos <- which(vars == var_interest)
60+
# for (k in 1:num_comb) {
61+
# formula <- formula(mods[[k]])
62+
# m1 <- mods[[k]]
63+
# pval[k] <- coef(summary(m1))[pos + 1, 4]
64+
# eval[k] <- coef(m1)[pos + 1]
65+
# data$ytemp <- data[, yvar] - coef(m1)[pos + 1] * (data[,
66+
# var_interest])
67+
# temp <- "ytemp ~ "
68+
# for (j in 1:nvar) temp <- paste(temp, paste("+",
69+
# all.vars(formula(mods[[k]]))[-1][j]))
70+
# formulak <- formula(temp)
71+
# set.seed(1)
72+
# bt <- boot::boot(data, function(d, i) coef(summary(update(mods[[k]],
73+
# data = d[i, ], formula = formulak)))[pos + 1, c(1,
74+
# 4)], R = B, stype = "i")
75+
# eboot[, k] <- bt$t[, 1]
76+
# pboot[, k] <- bt$t[, 2]
77+
# if (verbatim)
78+
# show(paste("model", k))
79+
# }
80+
# list(pval = pval, eval = eval, pboot = pboot, eboot = eboot,
81+
# models = mods)
82+
# }
83+
#

R/join_flipscores.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
#'jointest for flipscores objects
2-
#'@param tested_coeff is a list of the same length of \code{mods}, each element of the list being a vector of
2+
#'@param mods list of \code{glm}s (or list of any other object that can be evaluated by flipscores)
3+
#'@param tested_coeffs is a list of the same length of \code{mods}, each element of the list being a vector of
34
#'of names of tested coefficients. Alternatively, it can be a vector of names of tested coefficients, in this case, the tested coefficients are attributed to all models (when present).
45
#'As a last option, it can be \code{NULL}, if so, all coefficients are tested.
6+
#'@param n_flips = 5000
7+
#'@param score_type any valid type for \code{flipscores}, \code{"standardized"} is the default. see \code{\link[flipscores]{flipscores}} for more datails
8+
#'@param statistics "t" is the only method implemented (yet). Any other value will not modify the Score (a different statistic will only affect the multivariate inference, not the univariate one).
9+
#'@param seed \code{NULL} by default. Use a number if you wanto to ensure replicability of the results
10+
#'@param ... any other further parameter.
511
#'@export
612
#'
713
#'@examples
@@ -59,10 +65,13 @@ join_flipscores <- function (mods, tested_coeffs = NULL, n_flips = 5000, score_t
5965
colnames(tt) = colnames(temp$Tspace)
6066
temp$Tspace = tt
6167
}
68+
temp$summary_table=.get_summary_table_from_flipscores(temp)
6269
temp
6370
})
64-
65-
names(modflips) = names(mods)
66-
class(modflips) <- c("jointest", class(modflips))
71+
if(is.null(names(mods))){
72+
names(modflips)=paste0("mod",1:length(modflips))
73+
} else
74+
names(modflips) = names(mods)
75+
class(modflips) <- unique(c("jointest", class(modflips)))
6776
modflips
6877
}

R/jointest_package.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@
3131
#'
3232
#' @author Livio Finos
3333
#' @name jointest-package
34+
#' @importFrom stats median
35+
#' @importFrom stats qnorm
36+
#' @importFrom stats quantile
37+
#' @importFrom stats update
3438
NULL

0 commit comments

Comments
 (0)