From 7af01d594acaf949ef1d4bbe22142b45345b8b20 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Fri, 2 Sep 2016 15:39:30 +1000 Subject: bugfix + check for same length vectors --- R/pmt.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/pmt.R b/R/pmt.R index 9466b31..5921638 100644 --- a/R/pmt.R +++ b/R/pmt.R @@ -15,9 +15,11 @@ pmt <- function(a, b, two.sided=T, signed=F) { if(any(a == 0) | any(b == 0)) stop("cannot handle 0 counts") + if(length(a) != length(b)) + stop("vectors must be same length") ce <- function(mu){ - pt1 <- mapply(function(xa, mu, rho) logsumexp(cumsum(log(((1 + rho) * (xa - (0:xa-1))/(2 * mu))))), a, mu, rho) + pt1 <- mapply(function(xa, mu, rho) logsumexp(cumsum(log(((1 + rho) * (xa - (0:(xa-1)))/(2 * mu))))), a, mu, rho) pt2 <- mapply(function(xb, mu, rho) logsumexp(cumsum(log((2*mu*rho) / ((1 + rho)*(xb + (1:100)))))), b, mu, rho) rho + rho * (exp(pt1) - exp(pt2)) } -- cgit v1.2.3