Search

Tuesday, January 02, 2007

Great article: EDA for HLMs

There's an interesting paper I just read that comes with Sweave/R code that the article uses:

http://www-personal.umich.edu/~jwbowers/papers.html

It's called EDA for HLMs, and advocates an exploratory data analysis when trying to understand data (as opposed to blindly searching for a yes/no answer, did significance fall below 0.05). In psycholinguistics, we are still a long way from conventional plodding along well beaten paths.

Installing weaver

It is not immediately obvious how one can install weaver (thanks to balajis for telling me about it--see his comment to the Sweave speed issues).

Do the following as superuser for a system-wide install:

1. install digest (from CRAN)
2. install codetools from http://bioconductor.org/packages/1.9/omegahat/html/codetools.html
3. install weaver from http://www.bioconductor.org/packages/1.9/bioc/html/weaver.html

A clunky way to install on Mac OS X and Linux is: as superuser do

R CMD INSTALL packagetarball

I'll add information on how to use it later, but one can always consult the weaver manual/vignette.

How I maintain my data

As soon as you have a lot of experiments floating around, you tend to get a proliferation of code and data files. Usually, chaos ensues. If someone asks you for the data of some experiment you published, you can (a) ignore the request (this is the most economical but also the least ethical response) (b) send them they can realistically use. This post is about how to carry out (b).

Example.

Suppose I have a collection of data and R code that I will cryptically call intml.

1. package.skeleton("intml")
This will create some directories (see previous post)
2. now add the data to the data directory
3. add the .Rnw file you used to analyze the data as a vignette

Build a package as indicated in the last post, and send it to the person who asked for it. Or make it available on CRAN.

It's simple and it enforces a certain self-discipline. Nothing like the knowledge that anyone can read your code to force you to write it properly :-)

Monday, January 01, 2007

Putting together a library

The Introduction to R and other documentation CRAN tells you how to build a library. But it is remarkably hard to find a step-by-step how-to for packaging together an R library. Here is a good one.

Wednesday, December 13, 2006

Sweave for complex projects (speed issues)

One problem my colleagues and I face is that our statistical analysis projects quickly become very complex, and recompiling Sweave becomes a slow process each time I update the code or just run it again.

I am slowly compiling a list of available solutions to this problem (the real issues are lack of speed, lack of modularity):

Here is what I have found so far:

1. Use \SweaveInput for including modular code
2. Use makefiles a la Deepayan Sarkar:
here
3. Another solution that relates to the present problem:
here
4. Finally, I think one should make vignettes/packages out of one's research projects so that the whole Rnw file does not need to be compiled--the needed objects can be made visible by doing something like:

library(mydata)

There is a bit of work involved in making the package, but the payoff is tremendous. The R documentation provides details on how to build packages, but maybe I will put a simple example here.

Friday, September 15, 2006

How to compute min-F

Here's how to compute minF in R. You have to give the function the F1 and F2 values and the denominator dfs for each: minf(f1,f2,n1,n2).

minf <- function(f1,f2,n1,n2){
fprime <- (f1*f2)/(f1+f2)
n <- round(((f1+f2)*(f1+f2))/(((f1*f1)/n2)+((f2*f2)/n1)))
return(paste("minF(",n,")=",round(fprime,digits=2),", crit=",round(qf(.95,1,n)),sep=""))
}

If there are any mistakes here, corrections are welcome.

References: Raaijmakers' 1999 and 2003 articles.

Monday, February 13, 2006

Sweave introduction

Sweave is a package that comes with R, and can be used to interleave LaTeX and R code. Here's how I use it:

(I'm assuming you've got R installed on your machine.)

1. Download the bash script Sweave.sh from here. Install it in your bin directory, and be sure to change the first line to reflect the location of your bash.

2. Download the file Sweave-test-1.Rnw into a temporary directory.

3. cd to that directory and now run the script on this file:
Sweave.sh Sweave-test-1.Rnw. If all goes well, you have a .tex file Sweave-test-1.tex.

4. Compile the .tex file in whatever way is usual for you. The Sweave FAQ is a must-read.