From ebe86e0b2a3c3ba5594290b370ef616109a0ec85 Mon Sep 17 00:00:00 2001 From: michellepistner Date: Wed, 25 Oct 2023 14:34:26 -0400 Subject: [PATCH 1/2] Updating the constant mismatch Manan found --- src/SpecialFunctions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SpecialFunctions.cpp b/src/SpecialFunctions.cpp index c914e46..60731eb 100644 --- a/src/SpecialFunctions.cpp +++ b/src/SpecialFunctions.cpp @@ -10,7 +10,7 @@ using namespace Rcpp; double lmvgamma(double a, int p){ static const double pi = log(3.14159265); double s=0; - double x = pi*(p*(p-1.0))/2.0; + double x = pi*(p*(p-1.0))/4.0; for (int i=1; i<=p; i++){ s += lgamma(a+(1.0-i)/2); } From 0b935f79b9353d843fc58a1d9c697698daead2b1 Mon Sep 17 00:00:00 2001 From: michellepistner Date: Tue, 9 Apr 2024 15:36:25 -0400 Subject: [PATCH 2/2] fixing predict bug --- .github/workflows/R-CMD-check.yaml | 2 +- R/fidofit_methods.R | 7 +++++++ tests/testthat/test-pibble.R | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 2cdce5e..cff804e 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -2,7 +2,7 @@ # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: [main, master, parallel-fixes, remote-repo-fixes, develop, documentation-fixes, bug-fixes] + branches: [main, master, parallel-fixes, remote-repo-fixes, develop, plot-bug-fix] pull_request: branches: [main, master] diff --git a/R/fidofit_methods.R b/R/fidofit_methods.R index 6ada124..eeca7e4 100644 --- a/R/fidofit_methods.R +++ b/R/fidofit_methods.R @@ -673,6 +673,13 @@ predict.pibblefit <- function(object, newdata=NULL, response="LambdaX", size=NUL Pi <- to_proportions(as.pibblefit(object[com]))$Eta } Ypred <- array(0, dim=c(object$D, nnew, iter)) + + # Fixing small bug. If newdata is a single sample, then size will be a vector. + # The loop with rmultinom will break as a result unless size is transformed to a matrix. + + if(is.vector(size)){ + size <- matrix(size, nrow = 1) + } for (i in 1:iter){ for (j in 1:nnew){ Ypred[,j,i] <- rmultinom(1, size=size[j,i], prob=Pi[,j,i]) diff --git a/tests/testthat/test-pibble.R b/tests/testthat/test-pibble.R index b808372..6c0fe23 100644 --- a/tests/testthat/test-pibble.R +++ b/tests/testthat/test-pibble.R @@ -200,3 +200,13 @@ test_that("init argument words in refit", { expect(TRUE, "init argument not working in refit") }) +test_that("predict works with one sample", { + fit <- pibble(sim$Y, sim$X) + preds <- predict(fit, newdata = matrix(sim$X[,1], ncol = 1), response = "LambdaX") + preds <- predict(fit, newdata = matrix(sim$X[,1], ncol = 1), response = "Eta") + preds <- predict(fit, newdata = matrix(sim$X[,1], ncol = 1), response = "Y") + + expect_true(TRUE) +}) + +