Skip to content

Commit b2a1c2f

Browse files
authored
Update Birth.Death.Delay.R
1 parent cb3c791 commit b2a1c2f

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

Birth.Death.Delay.R

+8-14
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,16 @@ BDD <- function(indata, scale = 1, B = 0, nrepeat, tun.B, tun.al, tun.be,
8686
# This function calculates kappa Eq. (5) and Eq. (6) in Supplement and gamma_k(m, Delta) in page 3.
8787
# Returning the cumulative sum of kappa: sum_{m=0}^{i}kappa(delta,m) in Eq. (6) in Supplement.
8888
# P: shape parameter alpha and rate parameter of beta in gamma delay distribution.
89-
KI <- function(P,ti=time) {
90-
a <- P[1] #shape parameter alpha of gamma distribution in Eq. (5) and Eq. (6) in Supplement
91-
b <- P[2] #rate parameter beta of gamma distribution in Eq. (5) and Eq. (6) in Supplement .
92-
kappa <- rep(0, ti)
93-
for (m in 2:ti) { #discretized integral kappa(delta, m) of Eq. (5) and Eq. (6) in Supplement
94-
kappa[m] = pgamma((m-0.5),a, rate = b) - pgamma(((m-1)-0.5), a, rate = b)
95-
}
96-
kappa[1] = pgamma(0.5, a, rate = b)
97-
k.j <- rep(1, ti) # cumulative sum of kappa until i
98-
for (m in 1:ti) {
99-
k.all <- 0
100-
for (j in 1:m) k.all <- k.all + kappa[j]
101-
k.j[m] <- k.all
89+
KI <- function(P, ti=time){
90+
a = P[1]; #shape parameter alpha of gamma distribution in Eq. (5) and Eq. (6) in Supplement
91+
b=P[2]; #rate parameter beta of gamma distribution in Eq. (5) and Eq. (6) in Supplement .
92+
f <-function(x) pgamma(x,a,rate=b)
93+
k.j = rep(1,ti)
94+
for (m in 1:ti){ #discretized integral kappa(delta, m) of Eq. (5) and Eq. (6) in Supplement
95+
k.j[m] = integrate(f,m-1,m)$value
10296
}
10397
return(k.j)
104-
}
98+
}
10599

106100

107101

0 commit comments

Comments
 (0)