#' Get data at all scales.
#'
#' This function takes a matrix x of Poisson counts, nind by 2^k, and returns a nind by (2*2^k)-2 matrix that sums up columns of x at different scales. The last two columns of the aggregate are the sums of the first half of x and the sums of the second half. This function is needed to estimate the pi-s by aggregating data from multiple regions.
haar.aggregate= function(x){
if(is.vector(x)){dim(x)<- c(1,length(x))} #convert x to matrix
y = x
k = log2(ncol(x))
for(i in 1:(k-1)){
nc = ncol(x)
oddcols = ((1:nc) %% 2)==1
x = x[,!oddcols,drop="FALSE"]+x[,oddcols,drop="FALSE"]
y = cbind(y,x)
}
y
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.