a b/partyMod/tests/TestStatistic-regtest.R
1
2
set.seed(290875)
3
library("party")
4
5
### get rid of the NAMESPACE
6
attach(asNamespace("party"))
7
8
### 
9
###
10
###    Regression tests for test statistics
11
###    
12
###    functions defined in file `./src/TestStatistic.c'    
13
14
### tests for function C_maxabsTeststatistic
15
xf <- gl(3, 10)
16
yf <- gl(3, 10)[sample(1:30)]
17
x <- sapply(levels(xf), function(l) as.numeric(xf == l))
18
colnames(x) <- NULL
19
y <- sapply(levels(yf), function(l) as.numeric(yf == l))
20
colnames(y) <- NULL
21
weights <- sample(1:30)
22
linstat <- LinearStatistic(x, y, weights) 
23
expcov <- ExpectCovarLinearStatistic(x, y, weights)
24
maxabs <- max(abs(linstat - expcov@expectation) / sqrt(diag(expcov@covariance)))
25
stopifnot(isequal(maxabs, 
26
    maxabsTestStatistic(linstat, expcov@expectation, expcov@covariance, 1e-10)))
27
expcov@covariance[1,1] <- 1e-12
28
stopifnot(isequal(maxabs,
29
    maxabsTestStatistic(linstat, expcov@expectation, expcov@covariance, 1e-10)))
30
31
### tests for function C_quadformTeststatistic
32
### -> see LinearStatistic-regtest.R
33