-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathtsallisaccum.R
53 lines (53 loc) · 1.73 KB
/
tsallisaccum.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
`tsallisaccum` <-
function (x, scales = seq(0, 2, 0.2), permutations = 100, raw = FALSE,
subset, ...)
{
if (!missing(subset))
x <- subset(x, subset)
x <- as.matrix(x)
if (!is.numeric(x))
stop("input data must be numeric")
n <- nrow(x)
p <- ncol(x)
if (p == 1) {
x <- t(x)
n <- nrow(x)
p <- ncol(x)
}
pmat <- getPermuteMatrix(permutations, n)
permutations <- nrow(pmat)
m <- length(scales)
result <- array(dim = c(n, m, permutations))
dimnames(result) <- list(pooled.sites = c(1:n), scale = scales,
permutation = c(1:permutations))
for (k in 1:permutations) {
result[, , k] <- as.matrix(tsallis((apply(x[pmat[k,],
], 2, cumsum)), scales = scales, ...))
}
if (raw) {
if (m == 1) {
result <- result[, 1, ]
}
}
else {
tmp <- array(dim = c(n, m, 6))
for (i in 1:n) {
for (j in 1:m) {
tmp[i, j, 1] <- mean(result[i, j, 1:permutations])
tmp[i, j, 2] <- sd(result[i, j, 1:permutations])
tmp[i, j, 3] <- min(result[i, j, 1:permutations])
tmp[i, j, 4] <- max(result[i, j, 1:permutations])
tmp[i, j, 5] <- quantile(result[i, j, 1:permutations],
0.025)
tmp[i, j, 6] <- quantile(result[i, j, 1:permutations],
0.975)
}
}
result <- tmp
dimnames(result) <- list(pooled.sites = c(1:n), scale = scales,
c("mean", "stdev", "min", "max", "Qnt 0.025", "Qnt 0.975"))
}
attr(result, "control") <- attr(pmat, "control")
class(result) <- c("tsallisaccum", "renyiaccum", class(result))
result
}