These functions are used internally by relltest
for computing raw bootstrap probabilities of phylogenetic inference.
Alternatively, we used pvclust
to get raw bootstrap probabilities
of hierarchical clustering. In other cases, users may utilize
scaleboot
function or prepare their own functions.
scaleboot
performs multiscale bootstrap resampling for a
statistic defined by fun
, which should be one of the two
possible forms fun(x,w,parm)
and fun(x,i,parm)
. The former
is used when weight=TRUE
, and the weight
vector w
is generated by a multinomial distribution. The latter
is used when weight=FALSE
, and the index
vector i
is generated by resampling \(n'\) elements from
\(\{1,...,n\}\). When count=TRUE
, fun
should return
a logical, or a vector of logicals.
Examples of fun(x,w,parm)
are countw.assmax
for AU p-values,
countw.shtest
for SH-test of trees, and countw.shtestass
for SH-test of both trees and edges. The definitions are given below.
countw.assmax <- function(x,w,ass) {
y <- maxdif(wsumrow(x,w)) <= 0 # countw.max
if(is.null(ass)) y
else {
z <- vector("logical",length(ass))
for(i in seq(along=ass)) z[i] <- any(y[ass[[i]]])
z
}
}countw.shtest <- function(x,w,obs) maxdif(wsumrow(x,w)) >= obs
countw.shtestass <- function(x,w,assobs)
unlist(assmaxdif(wsumrow(x,w),assobs$ass)) >= assobs$obs
### weighted sum of row vectors
##
## x = matrix (array of row vectors)
## w = weight vector (for rows)
##
wsumrow <- function(x,w) {
apply(w*x,2,sum)*nrow(x)/sum(w)
}
### calc max diff
##
## y[i] := max_{j neq i} x[j] - x[i]
##
maxdif <- function(x) {
i1 <- which.max(x) # the largest element
x <- -x + x[i1]
x[i1] <- -min(x[-i1]) # the second largest value
x
}
### calc assmaxdif
##
## y[[i]][j] := max_{k neq ass[[i]]} x[k] - x[ass[[i]][j]]
##
assmaxdif <- function(x,a) {
y <- vector("list",length(a))
names(y) <- names(a)
for(i in seq(along=a)) y[[i]] <- max(x[-a[[i]]]) - x[a[[i]]]
y
}
When count=TRUE
, the summation of outputs from fun
is
calculated. This gives the frequencies for how many times the
hypotheses are supported by the bootstrap replicates.