From c403ba92f1e1fc4ca9c78091189d34642093ae4a Mon Sep 17 00:00:00 2001 From: Paul Staab Date: Mon, 25 Jan 2016 10:23:40 +0100 Subject: [PATCH 1/3] use typesafe vapply instead of sapply --- R/coala_interface.R | 4 ++-- R/likelihood.R | 4 ++-- R/stat_cube.R | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/coala_interface.R b/R/coala_interface.R index d5b7ac9..5717c5d 100644 --- a/R/coala_interface.R +++ b/R/coala_interface.R @@ -185,9 +185,9 @@ coarsen_jsfs <- function(ja, part, part_hi = NULL) { part[[i]] <- c(0, part[[i]], dim(ja)[i]) } - z <- numeric(length = prod(sapply(part, length) - 1)) + z <- numeric(length = prod(vapply(part, length, numeric(1)) - 1)) combinations <- - expand.grid(lapply(sapply(part, length) - 1, ":", 1))[length(z):1, ] + expand.grid(lapply(vapply(part, length, numeric(1)) - 1, ":", 1))[length(z):1, ] for (i in 1:length(z)) { comb <- combinations[i, ] diff --git a/R/likelihood.R b/R/likelihood.R index 1778063..678381a 100644 --- a/R/likelihood.R +++ b/R/likelihood.R @@ -42,9 +42,9 @@ approximate_llh.jaatha_model <- function(x, data, param, glm_fitted, sim) { approximate_llh.jaatha_stat_basic <- function(x, data, param, glm_fitted, sim, scaling_factor) { - loglambda <- sapply(glm_fitted[[x$get_name()]], function(glm_obj) { + loglambda <- vapply(glm_fitted[[x$get_name()]], function(glm_obj) { glm_obj$coefficients %*% c(1, param) - }) + }, numeric(1)) # Calculate the Poission log-likelihood calc_poisson_llh(data, x, loglambda, sim, scaling_factor) diff --git a/R/stat_cube.R b/R/stat_cube.R index b7c73eb..f037725 100644 --- a/R/stat_cube.R +++ b/R/stat_cube.R @@ -29,7 +29,7 @@ stat_cube_class <- R6Class("stat_cube", inherit = stat_basic_class, } # Count the classes and return as vector - dims <- sapply(break_values, length) + 1 + dims <- vapply(break_values, length, numeric(1)) + 1 factors <- cumprod(c(1, dims[-length(dims)])) classes_int <- apply(locus_class, 1, function(x) sum((x - 1)*factors) + 1) tabulate(classes_int, nbins = prod(dims)) From 0ab2cab84a796f0b744ee02259107754cb5532f9 Mon Sep 17 00:00:00 2001 From: Paul Staab Date: Mon, 25 Jan 2016 10:24:07 +0100 Subject: [PATCH 2/3] remove faulty test --- tests/testthat/test-jaatha-function.R | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/testthat/test-jaatha-function.R b/tests/testthat/test-jaatha-function.R index d285b3f..3fb6ef0 100644 --- a/tests/testthat/test-jaatha-function.R +++ b/tests/testthat/test-jaatha-function.R @@ -34,14 +34,3 @@ test_that("it supports a one parameter model", { expect_equal(results$args$cores, 1) expect_equal(results$args$max_steps, 15) }) - - -test_that("An error is thrown if all glms fail to converge", { - model <- create_jaatha_model(function(x) rpois(10, x), - par_ranges = matrix(c(0.1, 0.1, 10, 10), 2, 2), - sum_stats = list(create_jaatha_stat("null", function(x, y) 0)), - test = FALSE) - data <- create_test_data(model) - - expect_error(jaatha(model, data, repetitions = 2, sim = 10, cores = 1)) -}) From a421b16edc6764001bbf0722b6b5325889a2e0f6 Mon Sep 17 00:00:00 2001 From: Paul Staab Date: Mon, 25 Jan 2016 10:25:35 +0100 Subject: [PATCH 3/3] update version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 102378f..d41ccd8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: jaatha -Version: 3.0.0.9007 -Date: 2016-01-06 +Version: 3.0.0.9008 +Date: 2016-01-25 License: GPL (>= 3) Title: Simulation-Based Maximum Likelihood Parameter Estimation Authors@R: c(