Description Usage Arguments Details Value Author(s) Examples
View source: R/andrewsProjection.R
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.
1 | andrewsProjection(x, breaks = 30)
|
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 |
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 -π and π.
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
Yann Abraham
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 | # 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')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.