Skip to content

Freeze of Debian Squeeze – gedit-r-plugin 0.7.0.4-1 will not make it

Since we have freeze of Debian Squeeze, new features are not accepted any more and only important bug fixes can be excused and uploaded into testing, latest version 0.7.0.4-1 of gedit-r-plugin will not make it.

However the same packages that will be uploaded to unstable can be obtained from my private mirror

wget http://www.kaduk.net/~mateusz/gedit-r-plugin/kaduk.asc  ; cat kaduk.asc | apt-key add -
echo "deb http://www.kaduk.net/~mateusz/gedit-r-plugin ./" >> /etc/apt/source.list
apt-get update
apt-get install gedit-r-plugin

Categories: Uncategorized.

Cross-correlation with weights for missing samples

I implemented cross-correlation function in order to correct for missing samples.

meanx <- function(x,wx,tau) {
    return(sum(x[(tau+1):length(x)] * wx[(tau+1):length(wx)]) / sum(wx[(tau+1):length(wx)]));
}
meany <- function(y,wy,tau) {
    return(sum(y[1:(length(y)-tau)] * wy[1:(length(wy)-tau)]) / sum(wy[1:(length(wy)-tau)]));
}
 
sccf <- function(x,y,tau) {
    wx = as.numeric(x!=0);
    wy = as.numeric(y!=0);
    w = as.numeric(wx[(tau+1):length(wx)] & wy[1:(length(wy)-tau)]);
    q = sum(w*(x[(tau+1):length(x)] - meanx(x,wx,tau)) * (y[1:(length(y)-tau)] - meany(y,wy,tau)));
    d = sqrt(sum((w*(x[(tau+1):length(x)] - meanx(x,wx,tau)))^2)) *  sqrt(sum((w*(y[1:(length(y)-tau)] - meany(y,wy,tau)))^2));
    r = q/d;
    return(r);
}
 
mccf <- function(x,y,tau) {
    rlist = 0;
    for(jtau in (-tau):tau) {
        if(jtau < 0) {
            tmp = y;  y = x;   x = tmp;
            jtau = -jtau;
        }
        r = sccf(x,y,jtau);    
    rlist <- c(rlist,r);
    }
    return(cbind(rlist[2:length(rlist)], (-tau):tau));
}

Categories: R.

Gedit R integration plugin

Recently I packaged RGedit for GNU/Linux – Debian and it has been uploaded into sid gedit-r-plugin.

I also joined RGedit project at this time as second developer. My first intention was to maintain essential patches on upstream level, but in a spare time I also plan to contribute in

  • Code clean-up (with focus on porting glade->gtkbuilder)
  • New docbook documentation
  • New features development

Categories: GNU/Linux.

R implementation of ASCA

This is the implementation of ASCA for two factorial design(dosage and time)

# ASCA
anova_model <- function(input, Treatment, Subject, Time) {
    # Replace NAs
    input_w = is.na(input);
    input[input_w] = 0;
 
    # Mean center input
    Xc = apply(input,2,function(col) col-wmean(col));
    Xc[input_w] = 0;
 
    # Average over k to get X.k.
    X.k. = rep(0,max(Time)*ncol(Xc));
    dim(X.k.) <- c(max(Time),ncol(Xc));
    for(k in unique(Time)) {
        # Take into account number of treatments per subject
        colsum = colSums(Xc[Time == k,]);
        if(sum(colsum) != 0) { # Unless not available sample for all subjects
             n = sum(cbind(Treatment,Subject,(Xc[,1]!=0))[Time == k,][,3]); # Number of subjects used to calculated sum for given k
             colsum = colsum / n;
        }
        X.k.[k,] = colsum;
    }
 
    # Average over hk levels to get Xhk.
    Xhk. = rep(0,max(Time)*max(Treatment)*ncol(Xc));
    dim(Xhk.) <- c(max(Time)*max(Treatment),ncol(Xc));
    i = 0;
    for(h in unique(Treatment)) {    
        for(k in unique(Time)) {
            i=i+1;
            colsum = colSums(Xc[Treatment == h & Time == k,]);
            if(sum(colsum) != 0) { # Unless not available samples for all subjects
                n = sum(cbind(Treatment,Subject,(Xc[,1]!=0))[Treatment == h & Time == k,3]); # Number of subjects per hk level, max=5
                # Do the weighting
                weight = sqrt(n);
                # Calculate average
                colsum = (colsum / n) * weight;
            }
            # Put back intro matrix
            Xhk.[i,] = colsum;
        }
    }
 
    # Calculate interaction k&hk
    substraction = X.k.;
    for(i in 1:((dim(Xhk.)[1]/dim(X.k.)[1])-1)) {
        substraction = rbind(substraction,X.k.);
    }
    Xinteraction = Xhk. - substraction;
 
    # Calculate redisudals
    Xhki = Xc;
    substraction = Xhk.;
    for(i in 1:((dim(Xhki)[1] / dim(Xhk.)[1])-1)) {
        substraction = rbind(substraction,Xhk.);
    }
    Xresidual = Xhki - substraction;
 
    return(list(X.k. = X.k., XinteractionHK=Xinteraction, XresidualHKI=Xresidual));
}

Categories: R, Statistics.

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.

Categories: GNU/Linux.

Running R code within LaTeX with gedit-latex-plugin

To begin with download GeditLatexPlugin or if on debian

apt-get install gedit-latex-plugin

Secondly run gedit enabled LaTeX plugin and configure it, go to build profiles and change

R Sweave %e.Rnw

to

R CMD Sweave %f

After this changes you use R Sweave button to compile and to include your R code in LaTeX use

\begin{Scode}{fig=TRUE,echo=FALSE}
... R code ...
\end{Scode}

Categories: GNU/Linux.