1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
### test-calcType1postSelection.R ---
##----------------------------------------------------------------------
## author: Brice Ozenne
## created: sep 26 2017 (16:54)
## Version:
## last-updated: feb 11 2019 (13:45)
## By: Brice Ozenne
## Update #: 23
##----------------------------------------------------------------------
##
### Commentary:
##
### Change Log:
##----------------------------------------------------------------------
##
##
### Code:
## * header
rm(list = ls())
if(TRUE){ ## already called in test-all.R
library(testthat)
library(lavaSearch2)
}
library(testthat)
library(mvtnorm)
lava.options(symbols = c("~","~~"))
context("calcType1postSelection")
## * tests
n <- 350
test_that("check type 1 error - unrealistic case with independent statistics", {
p <- 5
p.all <- 2*p+1
zp <- qmvnorm(0.95, mean = rep(0,p), sigma = diag(1,p,p), tail = "both.tails")$quantile
type1Test <- calcType1postSelection(0.95,
quantile.previous = zp,
distribution = "gaussian",
mu = rep(0,p.all),
Sigma = diag(1,p.all,p.all),
correct = FALSE)
expect_equal(type1Test,0.05, tol = 0.01)
})
test_that("check type 1 error - 3 independent tests", {
#### 3 tests
Sigma <- diag(1,5,5)
Sigma[4,2] <- 1
Sigma[2,4] <- 1
Sigma[5,3] <- 1
Sigma[3,5] <- 1
## no selection since strong effect
mu <- c(10,0,0,0,0)
z2 <- qmvnorm(0.975, mean = mu[1:3], sigma = Sigma[1:3,1:3])$quantile
type1Test <- calcType1postSelection(0.95, quantile.previous = z2,
distribution = "gaussian",
mu = mu, Sigma = Sigma, correct = FALSE)
expect_equal(type1Test,0.05, tol = 0.01)
## conservative type 1 error due to selection
mu <- c(0,0,0,0,0)
z2 <- qmvnorm(0.975, mean = mu[1:3], sigma = Sigma[1:3,1:3])$quantile
type1Test <- calcType1postSelection(0.95, quantile.previous = z2,
distribution = "gaussian",
mu = mu, Sigma = Sigma, correct = FALSE)
expect_true(type1Test<0.05)
})
#----------------------------------------------------------------------
### test-calcType1postSelection.R ends here
|