aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2016-09-02 15:39:30 +1000
committerJustin Bedo <cu@cua0.org>2016-09-02 15:39:30 +1000
commit7af01d594acaf949ef1d4bbe22142b45345b8b20 (patch)
treee83666d83247438947bda2bb34433331ebc9f6ca
parent746fa5218a677b3651254701d257cc0367d9f1a6 (diff)
bugfix + check for same length vectors
-rw-r--r--R/pmt.R4
1 files changed, 3 insertions, 1 deletions
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))
}