=================================================================== RCS file: /cvs/ext/extinction_risk_1.R,v retrieving revision 1.11 retrieving revision 1.12 diff -u -p -r1.11 -r1.12 --- ext/extinction_risk_1.R 2015/08/06 11:08:24 1.11 +++ ext/extinction_risk_1.R 2015/08/06 13:09:31 1.12 @@ -1,5 +1,5 @@ # extinction_risk_1.R -# $Id: extinction_risk_1.R,v 1.11 2015/08/06 11:08:24 hako Exp $ +# $Id: extinction_risk_1.R,v 1.12 2015/08/06 13:09:31 hako Exp $ # # Author: Hiroshi Hakoyama # Copyright (c) 2013-2015 Hiroshi Hakoyama , All rights reserved. @@ -130,14 +130,14 @@ ext1 <- function(dat, t = 100, ne = 1, alpha = 0.05, v c(lower.CL.P, upper.CL.P) } - CI.rand <- function(mu.obs, s.obs, xd, t, q, tq, alpha) { + CI.rand <- function(mu.obs, xd, s.obs, t, tq, q, alpha) { mu <- rnorm(1, mean = mu.obs, sd = sqrt(s.obs / q)) s <- rchisq(1, df = q - 1) * s.obs / q confidence.interval(mu, xd, s, t, tq, q, alpha) } - CI.sim <- function(n.sim, gam, alpha, q, tq, t, xd, mu.obs, s.obs) { - CI.dist <- replicate(n.sim, CI.rand(mu.obs, s.obs, xd, t, q, tq, alpha)) + CI.sim <- function(n.sim, gam, alpha, mu.obs, xd, s.obs, t, tq, q) { + CI.dist <- replicate(n.sim, CI.rand(mu.obs, xd, s.obs, t, tq, q, alpha)) w.obs <- w(mu.obs, xd, s.obs, t) z.obs <- z(mu.obs, xd, s.obs, t) P.obs <- pr(w.obs, z.obs) @@ -155,8 +155,8 @@ ext1 <- function(dat, t = 100, ne = 1, alpha = 0.05, v c(binom$estimate[[1]], binom$p.value, ci) } - asymptotically.exact.confidence.interval <- function(n.sim, alpha.sim, alpha, q, t, xd, mu.obs, s.obs) { - res <- CI.sim(n.sim, alpha, alpha, q, tq, t, xd, mu.obs, s.obs) + asymptotically.exact.confidence.interval <- function(n.sim, alpha.sim, mu.obs, xd, s.obs, t, tq, q, alpha) { + res <- CI.sim(n.sim, alpha, alpha, mu.obs, xd, s.obs, t, tq, q) gg <- res[[1]] pp <- res[[2]] a <- alpha @@ -164,7 +164,7 @@ ext1 <- function(dat, t = 100, ne = 1, alpha = 0.05, v return(confidence.interval(mu, xd, s, t, tq, q, alpha)) } else { while (pp < alpha.sim) { - res <- CI.sim(n.sim, alpha, a, q, tq, t, xd, mu.obs, s.obs) + res <- CI.sim(n.sim, alpha, a, mu.obs, xd, s.obs, t, tq, q) gg <- res[[1]] pp <- res[[2]] a <- a * alpha / gg @@ -174,7 +174,7 @@ ext1 <- function(dat, t = 100, ne = 1, alpha = 0.05, v } if (exact.CL == TRUE) { - CL.P <- asymptotically.exact.confidence.interval(n.sim, alpha.sim, alpha, q, t, xd, mu, s) + CL.P <- asymptotically.exact.confidence.interval(n.sim, alpha.sim, mu, xd, s, t, tq, q, alpha) } else { CL.P <- confidence.interval(mu, xd, s, t, tq, q, alpha) }