Skip to content

Commit

Permalink
Trying to fix mixsqp convergence issues for some ashr tests run on wi…
Browse files Browse the repository at this point in the history
…nbuilder.
  • Loading branch information
pcarbo committed Feb 18, 2019
1 parent 564c5e2 commit edb0507
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Authors@R: c(person("Matthew","Stephens",role="aut",
person("Jason","Willwerscheid",role="aut"),
person("Nan","Xiao",role="aut"),
person("Mazon","Zeng",role="ctb"))
Version: 2.2-31
Date: 2019-02-07
Version: 2.2-32
Date: 2019-02-18
Title: Methods for Adaptive Shrinkage, using Empirical Bayes
Description: The R package 'ashr' implements an Empirical Bayes
approach for large-scale hypothesis testing and false discovery
Expand Down
17 changes: 11 additions & 6 deletions tests/testthat/test_binom.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
context("ashr with Binomial likelihoods")

test_that("lik_binom (identity link) fitted g is close to true g",{
test_that("lik_binom (identity link) fittced g is close to true g",{

# Simulate a Binomial dataset
set.seed(1)
trueg = unimix(c(0.5,0.5),c(0.5,0.1),c(0.5,0.9)) # true prior g: 0.5*U(0.1,0.9)+0.5*delta(0.5)
p = c(rep(0.5,500), runif(500,0.1,0.9)) # generate p from g
n = rep(100,1000)
x = rbinom(1000,n,p) # Binomial observations
ash.binom.out = ash(rep(0,length(x)),1,lik=lik_binom(x,n),g=trueg)
ash.binom.out = ash(rep(0,length(x)),1,lik = lik_binom(x,n),g = trueg,
control = list(delta = 0,maxiter.sqp = 40,
verbose = TRUE))

# Check if the estimated mixture proportion for components delta(0.5) and U(0.1,0.9)
# is close to the true mixture proportion (0.5,0.5)
Expand Down Expand Up @@ -52,18 +54,21 @@ test_that("lik_binom (identity link) with big n gives similar answers to normal
})

test_that("lik_binom (logit link) fitted g is close to true g",{

# Simulate a Binomial dataset
set.seed(1)
trueg = unimix(c(0.5,0.5),c(0,-3),c(0,3))
logitp = c(rep(0,500), runif(500,-3,3))
p = 1/(1+exp(-logitp))
n = rep(1000,1000)
x = rbinom(1000,n,p) # Binomial observations
ash.binom.out = ash(rep(0,length(x)),1,lik=lik_binom(x,n,link="logit"),
g=trueg,prior="uniform")
ash.binom.out = ash(rep(0,length(x)),1,lik = lik_binom(x,n,link = "logit"),
g = trueg,prior = "uniform",
control = list(verbose = TRUE))

# Check if the estimated mixture proportion for components delta(0.5) and U(-3,3)
# is close to the true mixture proportion (0.5,0.5)
# Check if the estimated mixture proportion for components
# delta(0.5) and U(-3,3) is close to the true mixture proportion
# (0.5,0.5).
expect_equal(ash.binom.out$fitted_g$pi, c(0.5,0.5), tolerance = 0.05)
})

Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test_pois.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ test_that("lik_pois (identity link) fitted g is close to true g",{
trueg = unimix(c(0.5,0.5),c(1,1),c(1,5)) # true prior g: 0.5*U(1,5)+0.5*delta(1)
lambda = c(rep(1,500), runif(500,1,5)) # generate lambda from g
x = rpois(1000,lambda) # Poisson observations
ash.pois.out = ash(rep(0,length(x)),1,lik=lik_pois(x),g=trueg)
ash.pois.out = ash(rep(0,length(x)),1,lik=lik_pois(x),g=trueg,
control = list(verbose = TRUE))

# Check if the estimated mixture proportion for components delta(0.5) and U(0.1,0.9)
# is close to the true mixture proportion (0.5,0.5)
Expand Down Expand Up @@ -53,7 +54,8 @@ test_that("lik_pois (log link) fitted g is close to true g",{
loglambda = c(rep(0,800), runif(200,-3,3))
lambda = exp(loglambda)
x = rpois(1000,lambda) # Poisson observations
ash.pois.out = ash(rep(0,length(x)),1,lik=lik_pois(x,link="log"),g=trueg)
ash.pois.out = ash(rep(0,length(x)),1,lik = lik_pois(x,link="log"),
g = trueg,control = list(verbose = TRUE))

# Check if the estimated mixture proportion for components delta(0) and U(-3,3)
# is close to the true mixture proportion (0.8,0.2)
Expand Down

0 comments on commit edb0507

Please sign in to comment.