-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_numeric.R
64 lines (59 loc) · 1.81 KB
/
test_numeric.R
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
cat("# numeric test\n")
library("qgcomp")
# are results at a given seed numerically stable across versions?
set.seed(50)
N=50
dat <- data.frame(time=(tmg <- pmin(.1,rweibull(N, 10, 0.1))),
d=1.0*(tmg<0.1), x1=runif(N), x2=runif(N), z=runif(N))
expnms=paste0("x", 1:2)
##### binomial
set.seed(123123)
f0 = d ~ x1 + x2
obj0a <- qgcomp(f0, expnms = expnms, data = dat, B=2, family=binomial())
obj0b <- qgcomp(f0, expnms = expnms, data = dat, family=binomial())
stopifnot(all.equal(
coef(obj0a),
c(-0.63497247,0.06082349 ),
check.names=FALSE, tolerance = 1e-4))
stopifnot(all.equal(
coef(obj0b),
c(-0.63497247,0.06082349 ),
check.names=FALSE, tolerance = 1e-4))
#' \dontrun{
#' ##### survival
#' set.seed(123123)
#' f1 = survival::Surv(tmg, d) ~ x1 + x2
#' obj1a <- qgcomp(f1, expnms = expnms, data = dat)
#' obj1b <- qgcomp.cox.boot(f1, expnms = expnms, B=2, data = dat)
#'
#' stopifnot(all.equal(
#' coef(obj1a),
#' c(0.02461938),
#' check.names=FALSE, tolerance = 1e-4))
#' stopifnot(all.equal(
#' coef(obj1b),
#' c(0.02654175),
#' check.names=FALSE, tolerance = 1e-4))
#'
#'
#' ##### zi
#' set.seed(123123)
#' f2 = d ~ x1 + x2 | x1 + x2
#' tm = pscl::zeroinfl(f2 , data=dat, dist="poisson")
#'
#' obj2a <- qgcomp.zi.noboot(f2, expnms = expnms, data = dat, dist="poisson")
#' obj2a <- qgcomp(f2, expnms = expnms, data = dat, family=poisson())
#' obj2b <- qgcomp.zi.boot(f2, expnms = expnms, data = dat, dist="poisson", B = 2)
#'
#' stopifnot(all.equal(
#' coef(obj2a),
#' list(count=c( -0.42823824,-0.05519007 ),
#' zero=c(9.057221, -40.356026)),
#' check.names=FALSE, tolerance = 1e-4))
#' stopifnot(all.equal(
#' coef(obj2b),
#' list(count=c( -0.43554489,-0.05279048 ),
#' zero=c(7.369426 , -18.411273)),
#' check.names=FALSE, tolerance = 1e-4))
#' }
cat("\n# done\n")