First order partial correlations in R

To calculate first order partial correlations in R efficiently, I implemented the pcor function in RcppArmadillo with recursive formula. The input of function is correlation matrix, and the output is three dimensional array with X,Y dimensions for correlated pairs, and extra Z dimension for all possible conditioning variables.

The GNU/Linux only version of package can be obtaind from link.

Encrypting external SSD drive with LUKS

First, make an empty partition with your favourite software (no filesystem).

gparted /dev/sdb

Than encrypt your disk and create file system

apt-get install cryptsetup
modprobe dm-crypt
cryptsetup --verbose --verify-passphrase luksFormat /dev/sdb1
cryptsetup luksOpen /dev/sdb1 SSD
mkfs.ext4 /dev/mapper/SSD
cryptsetup luksClose SSD

Umount disk, and connect it again, on Debian 6.0 (Gnome 3.2) it is automaticaly mounted and password prompting dialog pops up.

Maintaining LaTeX documents in GIT

First create the document folder and configure repository

sudo apt-get install git
mkdir mydocument
cd mydocument/
git init
vi .git/config

Add the following lines

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	autocrlf = true

[alias]
    wdiff = diff -w -b --ignore-space-at-eol --word-diff=porcelain --color

Now create .gitignore to skip files which are processing artefacts

vi .gitignore

And add the following entries

# Ignore LaTeX processing files
*.aux
*.log
*~
*.out
*.bbl
*.blg
*.dvi
*.pdf

Now add files to repository and commit

git add *
git commit -m "First commit"

Each time You change something You can use the following commands
git wdiff To see word-by-word changes
git log To see the history of changes
git commit To commit the differences
git help For other commands

Benchmark of Blas,Atlas,OpenBlas in R

To test the performance for different implementations of libraries used for matrix operations the following R code was used

library(microbenchmark);
n = 100;
prodAxA = function(A) {
A%*%t(A)
}
mtime = rep(0,n);
for(i in 1:n) {
A = matrix(runif(i^2),nrow=i,ncol=i);
mtime[i] = median(microbenchmark(prodAxA(A))$time)
}

All libraries were O3 optimized for Core2 processor family, by rebuilding packages according to standard rules provided by package maintainer on GNU/Linux Debian operating system.

The performance of following matrix operation
AA' was measured in nano-seconds 100 times and median time was recorded for from 1 to 100 matrix size.

According to results presented in the following figure, OpenBlas preformed best.

OpenBlas was 76% faster then original implementation and 36% faster then Atlas implementation.

Size Blas(Original) Lapack(Original) Blas(Atlas) Lapack(Atlas) Blas(OpenBlas) Lapack(Atlas)
100 1540240 542153 357314.5

The measurements were performed on Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz processor with performance governor.

First experience with RCytoscape

RCytoscape is a R plugin that allows graph drawing and layout methods of Cytoscape to be combined with statistical power of R.

I installed it from Bioconductor

source("http://bioconductor.org/biocLite.R")
biocLite("RCytoscape")

Additionally Cytoscape version 2.8 or above with CytoscapeRPC plugin 1.3 or above was required.
After enabling CytoscapeRPC.
Identity matrix was generated and ploted with

g < - new ("graphAM", adjMat = adMatrix, edgemode="undirected")
cw <- CytoscapeWindow("vignette", graph = g)
displayGraph(cw)
Posted in R

Matching port range with u32 filter

tc filter add dev eth0 parent 1:0 protocol ip prio 1 \
u32 \
match ip dst 192.168.1.100
match ip dport 0x400 0xB1DE flowid 1:1

To begin with first line is typical to all filtering rules, second stands for u32 filter usage and third for matching dst IP address. However the most interesting is 4th line which matches destination port range from 1024 to 20001.

The rule is the same as with IP address masks. The first 0×400 hex value stands for 1024 and the second is the mask. The mask is calculated (dec 20001) 0x4E21 XOR 0xffff = 0xB1DE.