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:
3. Another solution that relates to the present problem:
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:


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 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-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.