Running 'test_asis.R' [4s]
  Running 'test_basics.R' [3s]
  Running 'test_bayesqgcomp.R' [3s]
  Running 'test_boot_ints.R' [3s]
  Running 'test_bootchooser.R' [163s]
  Running 'test_factor.R' [3s]
  Running 'test_id.R' [3s]
  Running 'test_mice.R' [3s]
  Running 'test_multinomial.R' [0s]
  Running 'test_numeric.R' [160s]
  Running 'test_poisson.R' [157s]
  Running 'test_splits.R' [3s]
  Running 'test_weights.R' [160s]
Running the tests in 'tests/test_bootchooser.R' failed.
Complete output:
  > cat("# boot chooser test\n")
  # boot chooser test
  > library("qgcomp")
  > library("splines")
  > library("survival")
  > 
  > dgm <- function(N){
  +  dat <- data.frame(id=1:N) 
  +  dat <- within(dat, {
  +      time=(tmg <- pmin(.1,rweibull(N, 10, 0.1)))
  +      d=1.0*(tmg<0.1)
  +      u = 0
  +      x1 = runif(N)*4 + u
  +      x2 = runif(N)*4 + u
  +      x3 = runif(N)*4 + u
  +      x4 = runif(N)*4 + u
  +      x5 = runif(N)*4 + u
  +      x6 = runif(N)*4 + u
  +      y = rnorm(N, x1+x2, 2)
  + })
  +  dat[,c("y", "time", "d", paste0("x", 1:6))]
  + }
  > 
  > set.seed(11232)
  > dat = dgm(100)
  > Xnm = c(paste0("x", 1:6))
  > 
  > 
  > f = y~x1 + x2 + x3 + I(x3^2)
  > qgcomp(f, expnms = c("x1", "x2"), data = dat)
  Mixture slope parameters (bootstrap CI):
  
              Estimate Std. Error Lower CI Upper CI t value Pr(>|t|)
  (Intercept)  0.11343    0.42902 -0.72744  0.95429  0.2644   0.7921
  psi1         2.55385    0.24111  2.08129  3.02641 10.5921   <2e-16
  > qgcomp.noboot(f, expnms = c("x1", "x2"), data = dat)
  Scaled effect size (positive direction, sum of positive coefficients = 2.55)
     x1    x2 
  0.508 0.492 
  
  Scaled effect size (negative direction, sum of negative coefficients = 0)
  None
  
  Mixture slope parameters (Delta method CI):
  
              Estimate Std. Error Lower CI Upper CI t value Pr(>|t|)
  (Intercept)  0.35877    0.72969  -1.0714   1.7889  0.4917   0.6241
  psi1         2.55385    0.25209   2.0598   3.0479 10.1308   <2e-16
  > 
  > 
  > 
  > # should cause errors
  > f = y~. + .^2
  > res = try(qgcomp(f, data = dat), silent=TRUE)
  Including all model terms as exposures of interest
  
  > stopifnot(class(res)=="try-error")
  > 
  > fs = Surv(time,d)~. + .^2
  > res = try(qgcomp(fs, data = dat), silent=TRUE)
  Including all model terms as exposures of interest
  > stopifnot(class(res)=="try-error")
  > 
  > 
  > f = y~. 
  > res = try(fit1 <- qgcomp(f, expnms=Xnm, data = dat, parallel=TRUE), silent=TRUE)
  > stopifnot(class(res)=="try-error")
  > 
  > fs = Surv(time,d)~.
  > res = try(fit1 <- qgcomp(fs, expnms=Xnm, data = dat, B=5, MCsize=100), silent=TRUE)
  > stopifnot(class(res)=="try-error")
  > 
  > fs = Surv(time,d)~.
  > res = try(fit1 <- qgcomp(fs, expnms=Xnm, family=cox(), data = dat), silent=TRUE)
  > stopifnot(class(res)=="try-error")
  > 
  > #' \dontrun{
  > #' f = y~. + .^2
  > #' res = try(fit1 <- qgcomp(f, expnms=Xnm, data = dat), silent=TRUE)
  > #' stopifnot(inherits(res,"qgcompfit"))
  > #' 
  > #' fs = Surv(time,d)~. + .^2
  > #' res = try(fit1 <- qgcomp(fs, expnms=Xnm, data = dat, B=5, MCsize=100), silent=TRUE)
  > #' stopifnot(inherits(res,"qgcompfit"))
  > #' 
  > #' fs = Surv(time,d)~. + .^2
  > #' res = try(fit1 <- qgcomp(fs, expnms=Xnm, data = dat, B=5, MCsize=100, parallel=TRUE), silent=TRUE)
  > #' stopifnot(inherits(res,"qgcompfit"))
  > #' 
  > #' 
  > #' 
  > #' # splines splines do work
  > #' f = y ~ x2 + x3 + x4 + x5 + x6 + splines::ns(x1, df=2)
  > #' res = try(qgcomp(f, data = dat), silent=TRUE)
  > #' stopifnot(class(res)=="try-error") # should give error that expnms not defined
  > #' res = try(fit1 <- qgcomp(f, expnms=Xnm, q=8, data = dat, deg=2), silent=TRUE)
  > #' stopifnot(inherits(res,"qgcompfit"))
  > #' 
  > #' 
  > #' 
  > #' # splines splines do work
  > #' f = y ~ x2 + x3 + x4 + x5 + x6 + splines::ns(x1, df=2)
  > #' res = try(qgcomp(f, data = dat), silent=TRUE)
  > #' stopifnot(class(res)=="try-error") # should give error that expnms not defined
  > #' res = try(fit1 <- qgcomp(f, expnms=Xnm, q=8, data = dat, deg=2), silent=TRUE)
  > #' stopifnot(inherits(res,"qgcompfit"))
  > #' 
  > #' # splines splines + bayes
  > #' f = y ~ x2 + x3 + x4 + x5 + x6 + splines::ns(x1, df=2)
  > #' res = try(fit2 <- qgcomp(f, expnms=Xnm, q=8, data = dat, deg=2, bayes=TRUE), silent=TRUE)
  > #' stopifnot(inherits(res,"qgcompfit"))
  > #' 
  > #' 
  > #' # indicator functions
  > #' f = y ~ factor(x1) + x2 + x3 + x4 + x5 + x6
  > #' res = try(qgcomp(f, data = dat), silent=TRUE)
  > #' stopifnot(class(res)=="try-error") # should give error that expnms not defined
  > #' res = try(fit1 <- qgcomp(f, expnms=Xnm, q=8, data = dat, deg=3), silent=TRUE)
  > #' stopifnot(inherits(res,"qgcompfit"))
  > #' }
  > 
  > 
  > cat("done")
  done> 
  > proc.time()
     user  system elapsed 
     5.06    0.39    5.42 
Running the tests in 'tests/test_numeric.R' failed.
Complete output:
  > cat("# numeric test\n")
  # numeric test
  > 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")
  
  # done
  > 
  > proc.time()
     user  system elapsed 
     4.54    0.37    4.93 
Running the tests in 'tests/test_poisson.R' failed.
Complete output:
  > cat("# poisson test\n")
  # poisson test
  > library("qgcomp")
  > 
  > # grouped survival data
  > N = 250
  > t = 4
  > dat <- data.frame(row.names = 1:(N*t))
  > dat <- within(dat, {
  +   group = do.call("c", lapply(1:N, function(x) rep(x, t)))
  +   age = do.call("c", lapply(1:N, function(x) 1:t))
  +   u =  do.call("c", lapply(1:N, function(x) rep(runif(1), t)))
  +   x1 = rnorm(N, u)
  +   x2 = do.call("c", lapply(1:N, function(x) rep(sample(0:3,1), t)))
  +   time = runif(N*t, 20, 200)
  +   logtime = log(time)
  +   lograte = -5 + x1
  +   deaths = rpois(N, exp(log(time) + lograte)) 
  + })
  > 
  > summary(glm(deaths ~ x2, data = dat, family=poisson(), offset = logtime))$coefficients
                 Estimate Std. Error     z value    Pr(>|z|)
  (Intercept) -3.93507266 0.03661483 -107.472096 0.000000000
  x2          -0.05485667 0.02094406   -2.619199 0.008813653
  > 
  > res = qgcomp.noboot(deaths~x2 + offset(logtime), expnms="x2", data = dat, family=poisson(), q=NULL)
  > res = qgcomp.noboot(deaths~x2+x1 + offset(logtime), expnms=c('x1', "x2"), data = dat, family=poisson(), q=4)
  > summary(res)
  Mixture log(RR) (Delta method CI):
  
  $coefficients
                Estimate Std. Error   Lower CI   Upper CI   Z value Pr(>|z|)
  (Intercept) -5.6667845 0.06983329 -5.8036552 -5.5299138 -81.14733        0
  psi1         0.7583575 0.03870932  0.6824886  0.8342263  19.59108        0
  
  > 
  > res = qgcomp.noboot(deaths~x2+x1 + offset(logtime), expnms=c('x1', "x2"), data = dat, family=quasipoisson(), q=4)
  > 
  > 
  > # error by scoping for using the offset parameter
  > #qgcomp.noboot(deaths~x2, expnms="x2", data = dat, family=poisson(), q=4, offset = logtime)
  > 
  > # this doesn't fail, doesn't give correct intercept (offset is forgotten) and 
  > # variance looks wrong
  > #qgcomp.boot(deaths~x2 + offset(logtime), expnms="x2", data = dat, family=poisson(), parallel=TRUE,
  > #            q=NULL, B=500, MCsize = 1000)
  > 
  > 
  > 
  > # matching bootstrapped with non-bootstrapped version
  > dgm <- function(N){
  +  dat <- data.frame(id=1:N) 
  +  dat <- within(dat, {
  +      u = 0
  +      x1 = runif(N)*4 + u
  +      x2 = runif(N)*4 + u
  +      x3 = runif(N)*4 + u
  +      x4 = runif(N)*4 + u
  +      x5 = runif(N)*4 + u
  +      x6 = runif(N)*4 + u
  +      y = rpois(N, exp(-5+.3*x1+.3*x2))
  + })
  +  dat[,c('y', paste0("x", 1:6))]
  + }
  > 
  > Xnm = c(paste0("x", 1:6))
  > 
  > dat = dgm(200)
  > m1 = qgcomp.noboot(y~., expnms=Xnm, data = dat, family=gaussian(), q=4)
  > m1a = qgcomp(y~., expnms=Xnm, data = dat, family=gaussian(), q=4)
  > print(coef(m1), digits=10)
     (intercept)           psi1 
  -0.01615763918  0.02743842612 
  > 
  > #' \dontrun{
  > #' m1 = qgcomp.noboot(y~., expnms=Xnm, data = dat, family=poisson(), q=4)
  > #' m2 = qgcomp.boot(  y~., expnms=Xnm, data = dat, family=poisson(), q=4, B=5, parallel=TRUE, MCsize = 50)
  > #' print(coef(m1), digits=10)
  > #' print(coef(m2$msmfit), digits=10)
  > #' 
  > #' 
  > #' repit <- function(i){
  > #'   dat = dgm(1000)
  > #'   m1 = qgcomp.noboot(y~., expnms=Xnm, data = dat, family=poisson(), q=4)
  > #'   m2 = qgcomp.boot(  y~., expnms=Xnm, data = dat, family=poisson(), q=4, B=5, parallel=TRUE, MCsize = 100000)
  > #'   res = c(m1$coef, m1$var.coef, 1*(m1$pval>0.05), with(m1, ci.coef[1]<2 & ci.coef[2]>2), m2$coef, m2$var.coef, 1*(m2$pval>0.05), with(m2, ci.coef[2,1]<2 & ci.coef[2,2]>2))
  > #'   names(res) <- c("psiint", "psi", "varint", "var",  "powint", "pow",  "cover", "b.psiint", "b.psi", "b.varint", "b.var", "b.powint", "b.pow", "b.cover")
  > #'   res
  > #' }
  > #' 
  > #' 
  > #' #res = mclapply(1:1000, repit)
  > #' res = lapply(1:2, repit)
  > #' res = simplify2array(res)
  > #' 
  > #' # equality within toleraance
  > #' stopifnot(all.equal(res["psiint",],res["b.psiint",], tolerance=sqrt(0.01)))
  > #' stopifnot(all.equal(res["psi",],res["b.psi",], tolerance=sqrt(0.01)))
  > #' 
  > #' 
  > #' # bootstrap and regular variance good
  > #' repit2 <- function(i){
  > #'   dat = dgm(500)
  > #'   m1 = qgcomp.noboot(y~., expnms=c("x1", "x2"), data = dat, family=poisson(), q=4)
  > #'   m2 = qgcomp.boot(  y~., expnms=c("x1", "x2"), data = dat, family=poisson(), q=4, B=5, parallel=TRUE, MCsize = 1000)
  > #'   res = c(m1$coef, m1$var.coef, 1*(m1$pval>0.05), with(m1, ci.coef[1]<2 & ci.coef[2]>2), m2$coef, m2$var.coef, 1*(m2$pval>0.05), with(m2, ci.coef[2,1]<2 & ci.coef[2,2]>2))
  > #'   names(res) <- c("psiint", "psi", "varint", "var",  "powint", "pow",  "cover", "b.psiint", "b.psi", "b.varint", "b.var", "b.powint", "b.pow", "b.cover")
  > #'   res
  > #' }
  > #' 
  > #' #res = lapply(1:500, repit2)
  > #' #res = simplify2array(res)
  > #' 
  > #' 
  > #' #stopifnot(all.equal(res["var",],res["b.var",], tolerance=sqrt(0.01)))
  > #' 
  > #' }
  >   cat("done")
  done>  
  > 
  > proc.time()
     user  system elapsed 
     2.17    0.34    2.50 
Running the tests in 'tests/test_weights.R' failed.
Complete output:
  > cat("# weights test\n")
  # weights test
  > library("qgcomp")
  > # are results at a given seed numerically stable across versions?
  > set.seed(50)
  > N=100
  > 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))
  > dat$wt = runif(N)*40
  > dat$wt = dat$wt/mean(dat$wt)
  > dat$wt2 = 1
  > expnms=paste0("x", 1:2)
  > 
  > 
  > 
  > ##### binomial
  > set.seed(123123)
  > f0 = d ~ x1 + x2
  > obj0a <- qgcomp.noboot(f0, expnms = expnms, data = dat, family=binomial())
  > obj0b <- qgcomp.noboot(f0, expnms = expnms, data = dat, weight=wt2, family=binomial())
  > obj0c <- qgcomp.noboot(f0, expnms = expnms, data = dat, weight=wt, family=binomial())
  Warning message:
  In eval(family$initialize) : non-integer #successes in a binomial glm!
  > 
  > stopifnot(all.equal(
  +   coef(obj0a),
  +   coef(obj0b),
  +   check.names=FALSE, tolerance = 1e-4))
  > 
  > ##### 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
  > #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))
  > #
  > 
  > proc.time()
     user  system elapsed 
     2.26    0.29    2.54