## 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")

library(sspir)

## Thursday, May 5, 2011

### Solving R error "tar: Failed to set default locale" in Mac OS X

write the following in terminal

defaults write org.R-project.R force.LANG en_US.UTF-8

and restart R

## Tuesday, May 3, 2011

### Virtual Box Notes

To share folders from Linux Guest OS, we need to add the share folder and also install Virtual Box Additions

### Installing Octave and Gnuplot in Mac OS X

Solution copied from http://www.miscdebris.net/blog/2009/09/16/install-gnuplot-on-mac-os-x/

There are some possibilities to install Gnuplot on Mac OS X, none of them is “official”, since the Gnuplot project doesn’t provide binaries for Mac OS X. It’s actually quite easy to configure and compile Gnuplot (i.e. ./configure; make; make install), but some terminals are not built due to missing dependencies and this makes Gnuplot less powerful.

There is some information on the web about running Gnuplot on Mac OS X already (http://lee-phillips.org/info/Macintosh/gnuplot.html , http://maba.wordpress.com/2006/08/02/scientific-plotting-on-mac-os-x-using-gnuplot-and-plot/ ) and there is also http://www.finkproject.org/ and http://www.macports.org/ but there is IMO an easier way (though it still needs some work): there is a Gnuplot installer provided by Octave! Here are the instructions:

Open gnuplot-4.2.5-i386.dmg and copy Gnuplot.app to your Applications folder (or anywhere else).
That’s about it. Or at least it should be. Usually you just open Gnuplot.app and start plotting. But unfortunately the default aquaterm terminal doesn’t work for me always (on one Mac it did, on another it didn’t – maybe Aquaterm shouldn’t be installed before). So we need to hack Gnuplot.app so that X11 (which is also more powerful) becomes the default terminal.

Right click on Gnuplot.app and choose “Show Package Contents”.
Browse to Contents/Resources and edit “script” with your favorite text editor
Replace both lines do script (“exec ‘\${ROOT}/bin/gnuplot’”) with do script (“GNUTERM=x11 exec ‘\${ROOT}/bin/gnuplot’”) . X11 will then be the default terminal.
You might also want to have gnuplot available in your usual terminal session. This is also no problem. Just run the following command in your terminal