Learn R Programming

hilbertSimilarity (version 0.4.3)

andrewsProjection: Use Andrews plots to visualize the Hilbert curve

Description

Use a Fourier series to project the Hilbert curve, based on the number of points per Hilbert index. See Wikipedia - Andrews plot for a description of the method.

Usage

andrewsProjection(x, breaks = 30)

Arguments

x

a matrix of counts, where rows correspond to samples and columns to Hilbert index

breaks

the number of points used to display the Andrews curve

Value

a list with 2 items:

  • freq : a matrix with breaks rows and ncol(x) columns containing the Andrews vector for projection

  • i : a vector with breaks elements corresponding to the Andrews indices

Details

The Andrews curve corresponds to a projection of each item to \((1/2^0.5,sin(t),cos(t),sin(2t),cos(2t),...)\) where t (the Andrews index) varies between \(-\pi\) and \(\pi\).

Examples

Run this code
# NOT RUN {
# generate a random matrix
ncols <- 5
mat <- matrix(rnorm(ncols*1000),ncol=ncols)
dimnames(mat)[[2]] <- LETTERS[seq(ncols)]

# generate categories
conditions <- sample(letters[1:3],nrow(mat),replace = TRUE)
# generate 4 bins with a minimum bin size of 5
horder <- 4
cuts <- make.cut(mat,n=horder+1,count.lim=5)
# Generate the cuts and compute the Hilbert index
cut.mat <- do.cut(mat,cuts,type='fixed')
hc <- do.hilbert(cut.mat,horder)
# compute hilbert index per condition
condition.mat <- table(conditions,hc)
condition.pc <- apply(condition.mat,1,function(x) x/sum(x))
condition.pc <- t(condition.pc)
# project the matrix to the Andrews curve
av <- andrewsProjection(condition.pc)
proj <- condition.pc %*% t(av$freq)

plot(range(av$i),
     range(proj),
     type='n',
     xlab='Andrews index',
     ylab='Projection')
for(i in seq(nrow(proj))) {
    lines(av$i,
          proj[i,],
          col=i)
}
legend('bottomleft',
       legend=letters[1:3],
       col=seq(1,3),
       pch=16,
       bty='n')
# }

Run the code above in your browser using DataLab