pp.aggsum <- function (x, n) { # placed in the public domain 2011-2012 by Burns Statistics if (!is.numeric(n) || length(n) != 1 || n <= 0) { stop("bad value for 'n'") } if (n == 1) return(x) if(is.matrix(x)) { ismat <- TRUE } else { ismat <- FALSE xorig <- x x <- as.matrix(x) } nb <- nrow(x)%/%n nobs <- nb * n xm <- t(x[1:nobs, ]) dim(xm) <- c(ncol(x), n, nb) ans <- colSums(aperm(xm, c(2, 3, 1))) if(!ismat) { ans <- drop(ans) names(ans) <- names(xorig)[seq(n, by=n, length=nb)] } ans } pp.kurtosis <- function (x) { # placed in the public domain 2011-2012 by Burns Statistics if(is.data.frame(x)) x <- as.matrix(x) if(is.matrix(x)) { colMeans(scale(x, scale=FALSE)^4) / apply(x, 2, sd)^4 } else { mean((x - mean(x))^4) / sd(x)^4 } } pp.skew <- function (x) { # placed in the public domain 2011-2012 by Burns Statistics if(is.data.frame(x)) x <- as.matrix(x) if(is.matrix(x)) { colMeans(scale(x, scale=FALSE)^3) / apply(x, 2, sd)^3 } else { mean((x - mean(x))^3) / sd(x)^3 } }