-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathkrandboot.R
32 lines (27 loc) · 1.15 KB
/
krandboot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
as.krandboot <- function(obs, boot, quantiles = c(0.025, 0.975), names = colnames(boot), call = match.call()){
## obs: a vector (length p) with observed value of the statistic
## boot: a matrix (n p) with bootstrapped values
## n: number of repetitions, p number of statistics
if(ncol(boot) != length(obs))
stop("Wrong number of statistics")
res <- list(obs = obs, boot = boot)
res$rep <- apply(boot, 2, function(x) length(stats::na.omit(x)))
res$stats <- t(sapply(1:length(obs), function(i) obs[i] - stats::quantile(boot[,i] - obs[i], probs = rev(quantiles), na.rm = TRUE)))
colnames(res$stats) <- rev(colnames(res$stats))
if(is.null(names))
names <- 1: nrow(res$stats)
rownames(res$stats) <- names
res$call <- call
class(res) <- "krandboot"
return(res)
}
print.krandboot <- function(x, ...){
if (!inherits(x, "krandboot"))
stop("Non convenient data")
cat("Multiple bootstrap\n")
cat("Call: ")
print(x$call)
cat("\nNumber of statistics: ", length(x$obs), "\n")
cat("\nConfidence Interval:\n")
print(cbind.data.frame(N.rep = x$rep, Obs = x$obs, x$stats))
}