Monday, August 22, 2011

Rapid Miner and R extension problem on Mac solved

Suppose you are using R 2.12

Enter the following in either /etc/profile or ~/.bash_profile

PATH=$PATH:/Library/Frameworks/R.framework/Versions/2.12/Resources/bin:/Library/Frameworks/R.framework/Versions/2.12/Resources/library/rJava/jri
R_HOME=/Library/Frameworks/R.framework/Versions/2.12/Resources
export R_HOME

In the /Library/Frameworks/R.framework/Versions/2.12/Resources/library/rJava/jri/ folder, do the following:
1) Rename the JRI.jar to JRI.jar.original
2) make a copy of the libjri.jnilib and rename this copy to JRI.jar
This is because, by default it looks for JRI.jar

Once rapidminer is started, in the R preferences, change the rapid.miner.r.native lib file back to /Library/Frameworks/R.framework/Versions/2.12/Resources/library/rJava/jri/libjri.jnilib

Delete the JRI.jar (copied from libjri.jnilib)
Rename back JRI.jar.original to JRI.jar.


Wednesday, August 3, 2011

Download file from terminal MAC OSX versus Linux

On Mac, use:
curl -O ftp://abc.tar.gz &

On Linux, use:
wget ftp://abc.tar.gz &

Wednesday, June 15, 2011

Tutorial to create R packages

http://www.stat.ufl.edu/system/r-pkg-tut/

Tuesday, June 7, 2011

receiver operating characteristic (roc) and area under the curve (AUC) in matlab

Here is an implementation corresponding to Tom Fawcett's algorithm 3 in "roc graphs: notes and practical considerations for researchers, " 2004.

function auc=areaundercurve(FPR,TPR);
% given true positive rate and false positive rate calculates the area under the curve
% true positive are on the y-axis and false positives on the x-axis
% sum rectangular area between all points
% example: auc=areaundercurve(FPR,TPR);
[x2,inds]=sort(FPR);
x2=[x2,1]; % the trick is in inventing a last point 1,1
y2=TPR(inds);
y2=[y2,1];
xdiff=diff(x2);
xdiff=[x2(1),xdiff];
auc1=sum(y2.*xdiff); % upper point area
auc2=sum([0,y2([1:end-1])].*xdiff); % lower point area
auc=mean([auc1,auc2]);


function [TP,FP]=getfptp(T,Y)
Y(Y>=0)=1;Y(Y<0)=-1; % target class (positive) is 1
TP=sum( ( (Y==1) + (T==1) )==2 );
FN=sum( ( (Y==-1) + (T==1) )==2 );
FP=sum( ( (Y==1) + (T==-1) )==2 );
TN=sum( ( (Y==-1) + (T==-1) )==2 );
TP=TP/(TP+FN);
FP=FP/(FP+TN);
end

Saturday, June 4, 2011

How to read external drives in both Mac and Windows

Use a HFS explorer in Windows like http://www.catacombae.org/hfsx.html

Tuesday, May 31, 2011

R mean and std plot

Taken from http://monkeysuncle.stanford.edu/?p=485

First create the following function:
error.bar <- function(x, y, upper, lower=upper, length=0.1,...){
if(length(x) != length(y) | length(y) !=length(lower) | length(lower) != length(upper))
stop("vectors must be same length")
arrows(x,y+upper, x, y-lower, angle=90, code=3, length=length, ...)
}

Then try the example below:
y <- rnorm(500, mean=1)
y <- matrix(y,100,5)
y.means <- apply(y,2,mean)
y.sd <- apply(y,2,sd)
barx <- barplot(y.means, names.arg=1:5,ylim=c(0,1.5), col="blue", axis.lty=1, xlab="Replicates", ylab="Value (arbitrary units)")
error.bar(barx,y.means, 1.96*y.sd/10)

Sunday, May 8, 2011

Solving R error using kfilter matrix(NA, ss$n, ss$p) : non-numeric matrix extent

To solve the error before using SS, do a double transpose to the time series

example
the following works:

m2=NULL
m2 <- SS( t(t(ts(runif(100, 5.0, 7.5)))))
m2.n=1;
m2.p=1;
m2.f <- kfilter(m2)
plot(m2$y)
lines(m2$y,lty=2,col="green")
lines(m2.f$m,lty=2,col="red")

but dont forget to first install the sspir package using
install.packages("sspir")

and loading the library using
library(sspir)