Thursday, May 21, 2009

Multiple ANOVA tests in R by a grouping factor

If you have ever needed to run multiple ANOVA's according to or by a certain grouping factor here is your guide:

To do Type III sums of squares you'll need the car package. To split up your data by a grouping factor you'll need the doBy package.


Begin with a dataframe that has your factors, response, and grouping factor as columns (Y = response, A = factor A, B = factor B, Group = grouping factor)

If you have never read in data before into R, try something like this:

data<- read.table("/home/user/Desktop/data.txt")

I prefer to simply use text files that are delimited by space or tab.

Next name your columns:


Now you need to split your data up according to your grouping factor.


Lastly, run this loop:

i <-1 while(i <=length(data_split)){    
print (Anova(lm(Y~A+B+A*B, data_split[[i]]),type="III")[4,4])
i<- i +1

R output can be accessed in row and column fashion [r,c]. I have this particular code give me only the p-value from the interaction of factors A and B. By changing [4,4] to other numbers you can access whatever part of the ANOVA table you want. Hope this helps.

Friday, May 8, 2009

two-column default for wmii-ruby (sort of like xmonad)

How to default to 2 columns in wmii-ruby?

Add this to your wmiirc-config.rb file:

on_createclient do |cid|
tag = read("/client/#{cid}/tags")
# does the last line start with a "1", then only one column
if read("/tag/#{tag}/index").split("\n").last.match(/^1\s+/)
write("/tag/sel/ctl", "send sel right")

Basically, if you have one column of applications and you open another client, this will shove your client to the right, making a 2nd column. This should work on the wmii 3.5-3.6 series.

This (not going automatically into 2 columns) has bothered me a lot in the past and when I was trying out xmonad I found that they do this in the default layout. [It would be fun to implement the rest of the basic xmonad layouts in wmii-ruby...]

What is wmii-ruby? (in case you're asking)

I've been playing around again with wmii-ruby. wmii is a minimalist window manager for X11 (i.e., graphics on *nix-ish OS's) that is very scriptable and wmii-ruby is (you guessed it) wmii scripted in ruby. Best features:
  1. tiling window manager (use all your screen space)
  2. uses very flexible tagging system to keep things organized.
  3. very scriptable (see above example)
  4. can use a mouse but don't really need to
It really is aimed more at hacker-types than the general public, but it is quite educational figuring out how to do many of the things you take for granted with a more feature rich desktop like gnome or KDE.