massTtestCI: Mass t-tests with conditional inference

View source: R/massTtestCI.R

massTtestCIR Documentation

Mass t-tests with conditional inference

Description

Perform t-tests for all variables or only for variables showing a sufficiently large effect. In the latter case, conditional confidence intervals are used instead of the "normal" confidence intervals to account for the selection step.

Usage

massTtestCI(
  X,
  Y,
  threshold,
  conf.level = 0.95,
  method.p.adjust = "bonferroni",
  ...
)

Arguments

X

[numeric matrix] the design matrix for the individuals of the control group.

Y

[numeric matrix] the design matrix for the individuals of the experimental group.

threshold

[numeric] the selection threshold for the difference in mean between the groups.

conf.level

[numeric, 0-1] Confidence level.

method.p.adjust

[character] Method used to adjust for multiple comparisons. See argument method in p.adjust for more details.

...

additional arguments passed to the function conditionalCI.

Value

A data.frame where each site corresponds to a row and with the following columns:

  • site: the index of the site

  • estimate: the estimated mean difference

  • sigma: the estimated standard error of the estimated mean difference

  • statistic: the value of the test statistic

  • p.value: the (unadjusted) p-value

  • adjusted.p.value: the p-value adjusted for multiple comparisons over all sites

  • select: whether the site has been selected (i.e. signal above the threshold)

  • lower.CI: lower bound of the post-selection confidence interval (unadjusted)

  • upper.CI: upper bound of the post-selection confidence interval (unadjusted)

  • adjusted.lower.CI: lower bound of the post-selection confidence interval (adjusted for multiple comparisons over all selected sites)

  • adjusted.upper.CI: upper bound of the post-selection confidence interval (adjusted for multiple comparisons over all selected sites)

Examples


if(require(sp) & require(gstat)){

## settings
n.samples <- 20
n.sites <- 30*30

coords <- expand.grid(x = 1:sqrt(n.sites),
                     y = 1:sqrt(n.sites))
coords$mu <- 0
coords$mu[coords$x<=5 & coords$y<=5] <- 1

vario <- vgm(psill = 1, range = 2, model='Exp')

## simulate data
set.seed(10)

X <- sim2Dimage(n = n.samples,
                coords = coords[,c("x","y")],
                mu = 0,
                vgm = vario)$X

Y <- sim2Dimage(n = n.samples,
                coords = coords[,c("x","y")],
                mu = coords$mu,
                vgm = vario)$X

coords$meanX <- colMeans(X)
coords$meanY <- colMeans(Y)

spdf <- coords
spdf$effect <- coords$meanY - coords$meanX
gridded(spdf) <- ~x+y
effect.range <- range(spdf[["effect"]])

plot(spdf[,"effect"], zlim = effect.range)

res <- massTtestCI(X, Y, threshold = 0.5, method.CI = "shortest2")

## traditional analysis
spdf$p.value <- res$p.value
spdf$adjusted.p.value <- res$adjusted.p.value

plot(spdf[,"effect"], zlim = effect.range,
main = "traditional t-test")
points(spdf[spdf$adjusted.p.value<0.05,"p.value"], col = "green", lwd = 3)

## post selection CI
spdf$selected <- res$selected
spdf$lower.CI <- res$lower.CI
spdf$adjusted.lower.CI <- res$adjusted.lower.CI

plot(spdf[spdf$selected>0,"lower.CI"], zlim = effect.range,
     main = "post-selection unadjusted")
points(spdf[which(spdf$lower.CI>0),"lower.CI"], col = "green", lwd = 3)

plot(spdf[spdf$selected>0,"adjusted.lower.CI"], zlim = effect.range,
     main = "post-selection adjusted")
points(spdf[which(spdf$adjusted.lower.CI>0),"lower.CI"], col = "green", lwd = 3)
}


bozenne/butils documentation built on Oct. 14, 2023, 6:19 a.m.