Tuesday, December 15, 2009

Bayesian Optimal Discovery Procedure (BODP) R code

The r code given as an additional file to the paper Bayesian optimal discovery procedure for simultaneous significance testing requires your data to be in matrix form. I spent a day trying to troubleshoot the code when all you need to do is the following:

Open R
Copy and paste the R code from Cao et al.
x<-read.table("x.txt") #your control state
y<-read.table("y.txt") #your test state
BODP(x,y,1000,10) #feel free to change 1000 and 10 to whatever you'd like

Sunday, November 29, 2009

A thread I started a while ago suggests a solution to getting hibernation and suspend working properly with nvidia cards on Inspiron 5160 in Ubuntu. At least as of Karmic Koala (9.10), the solution one-line easier:

In the device section of /etc/X11/xorg.conf add the line:
Option "NvAGP" "1"

To /etc/modprobe.d/blacklist.conf add the following:
blacklist intel_agp

then reboot

slow browsing in firefox in Ubuntu 9.10 Karmic Koala

type in about:config into the browser bar

change the value of the key "network.dns.disableIPv6" from 'false' to 'true'

drastically increased browsing speed for me.

Saturday, November 14, 2009

a little Perl spice for ruby

An insightful blog post got me envying some of the brevity of Perl, so I implemented a couple useful idioms from Test::More in Ruby (which is pretty trivial since it allows opening up a class).

We'd like to have a really terse vocabulary when describing the most common test cases:

## equality
num = 8
num.should.equal 8 # bacon
num.must_equal 8 # minitest::spec
num.should == 8 # rspec
num.is 8 # clearly superior, similar to Test::More "is a, b"

## true/false
(num == 8).should.be.true # bacon
(num == 8).ok # superior, like Test::more "ok (something)"

So, for Bacon at least, this is all that needs to be done (put in your spec_helper.rb file)

class Object
def is(arg)
def ok
should.equal true

The argument against this would go, "well, it's better to be more verbose and understood". The counter-argument something like, "this still makes sense and is way easier to write, so I can write more spec's which == better code".

Monday, October 12, 2009

wxruby: wxWidgets for ruby on Ubuntu

A nice link on how to get the basic wxruby (wxWidgets for ruby) going on Ubuntu/debian.

Some examples in the examples folder require some more libraries. For instance, the opengl example requires libopengl-ruby (and maybe freeglut3 libglut [??]) and one of the drawing examples requires librmagick-ruby.

So this should be enough to get you going with most of the examples:
sudo apt-get install libwxbase2.8-{0,dev} libwxgtk2.8-{0,dev} librmagick-ruby libopengl-ruby
sudo gem install wxruby

Saturday, October 10, 2009

how to safely delete things in Ubuntu/Linux

I accidentally performed a `rm -rf` on a very big and important directory. I was able to recover close to half of the files using extundelete, but it still left me with a sour taste in my mouth. Now that there is a solid freedesktop specification for how to Trash things, it seems high time to remedy this situation.

In my ~/.bashrc file:
if [ ! `which gvfs-trash 2>/dev/null` ]
alias dl='mv -t ~/.Trash/' # for older systems
alias dl='gvfs-trash'
So, now we can simply dl files and they go to a safe place. Still, I find myself using rm, so this little alias will help cure my addiction, by reminding me that I should be using dl instead of rm. I can still use the rm command by putting it in single quotes (that's how to get past any alias) as in: 'rm' -rf some_directory.
alias rm="echo \"use dl or 'rm'\""

Wednesday, October 7, 2009

How to share a VirtualBox virtual machine with multiple users on Linux/Ubuntu

Have you ever wanted to share your virtual machine with other users? Doing so will save a lot of space (since you only need one virtual machine) and keep you more in line with the EULA of the distribution you are running virtual (assuming that's Windows or Mac).

There are many tutorials online (for example) that will help you to install VirtualBox on your linux machine. A couple things to note:
  1. You probably want to use the package from the VirtualBox download site (and not the open source one that you can get with apt-get) since it has many of the features that are important for a good virtual machine (like USB support and OpenGL acceleration etc).

  2. Make sure a vboxusers group was created and that everyone who would want to use the virtual machine is part of that group.
Prerequisite: right now the only way I can get this to work is if everyone wanting to share the virtual machine has sudo privileges. I'd be interested if anyone can suggest a way to do this without them. OK, we're ready to start:
  1. Make a shared directory for your virtual machines:
    sudo mkdir /var/local/VirtualBox
  2. Create a soft link from the home directory of each user sharing:
    ln -s /var/local/VirtualBox $HOME/.VirtualBox
  3. Now create a custom application launcher for your panel:
    sh -c "gksudo 'chown -R $USER:$USER /var/local/VirtualBox'; VirtualBox"
    (that command [or similar] could be wrapped up in a .bashrc function, a script placed in your $HOME/bin directory or whatever).
Also, remember when you buy your next computer to think about getting one with virtualization capabilities (for instance, an intel chart of core 2 duo desktop processors which support virtualization)

Sunday, September 20, 2009

Make coloring pages from any picture for free

Download and install GIMP.
windows download or ubuntu (sudo apt-get install gimp).


Filters -> Artistic -> Photocopy

A dialog box will allow you to adjust the sharpness and amount of black and white you want to see with a preview.

That's it!

Monday, August 3, 2009

starting with timidity and soundfonts on Ubuntu Linux

On the command line:
sudo aptitude install timidity

I like to have a folder with my timidity configuration files and soundfonts in my home directory:

Inside that folder I'll have my "master" configuration called "timidity.cfg" and a layout something like this (I'm actually omitting a lot here):

|-- Piano.cfg
|-- ensemble.cfg
|-- harpsichord.cfg
|-- organ.cfg
|-- patches
|   |-- eawpats12_full
|   |   |-- acbass.pat
|   |   |-- [...]
|-- soundfonts
|   |-- Ensemble
|   |   |-- Zemljak_Overture.sf2
|   |   |-- choir
|   |   |   |-- 052_Florestan_Ahh_Choir.sf2
|   |   |   |-- Boychoir.sf2
|   |   |   `-- boychoir.txt
|   |-- Organ
|   |   |-- GothicOrgan.sf2
|   |   |-- jeux14.sf2
|   |   `-- jeux2.sf2
|   |-- Piano
|   |   |-- ClavinovaGrandPiano2.sf2
|   |   |-- RolandPowerGrand.sf2
|   |   |-- harpsichord
|   |   |   |-- Blanchet-440_ver.1.0.sf2
|   |   |   |-- Campbells_Harpischord_tuned_1.sf2
|   |   |   `-- Petit_Italien.sf2

Now, we can edit the "global" configuration file to point to our timidity configuration file:

sudo gedit /etc/timidity/timidity.cfg
# Instrument configuration file for timidity
# $Id: timidity.cfg,v 1.7 2005/09/03 19:26:03 hmh Exp $

# [... omitting some for brevity ...]
# [ NOTE: With a recent CPU you can leave everything commented in this file no problem ]

# Include a configuration for the selected patchset or soundfont
# By default, try to use the instrument patches from freepats:

source /etc/timidity/freepats.cfg

## added by JTP ##
source /home/john/timidity/timidity.cfg

That file basically turns on freepats and then points to your home configuration. Timidity lets you "cascade" sounds, so activating freepats will ensure that you have some kind of sound for most of the banks accessed by your midi files. Any patches/soundfonts you later specify will override those previously specified.

Here's my timidity.cfg file:

dir /home/john/timidity
# (NOTE: I just comment out the config files I'm not using)
#source jeux14.cfg
#source organ.cfg
#source merlin.cfg
#source Piano.cfg

source harpsichord.cfg

The dir command just "activates" a given directory so that I can then call the configuration files in it by their basename as shown. With this configuration, I can set up lots of preconfigured sounds that I can easily turn on and off in my "master" configuration file.

OK, so now, lets get a soundfont and use it to play some music:

The Blanchet is my favorite harpsichord soundfont at the moment (Download the sf2 file Download the sf2 file). Turns out most sf2 files are compressed with sfark, so you need to download software to decompress it. After you decompress the soundfont, you'll want to look at the soundfont. Linux has a soundfont editor called "swami" that lets you see what's in a soundfont:

# only in Ubuntu 9.04 or earlier !!
sudo aptitude install swami
# you can fire it up with the soundfont on the command line if you want (or without)
swami timidity/soundfonts/Piano/harpsichord/Blanchet-440_ver.1.0.sf2
At least for Karmic and Lucid (9.10) you will need to follow instructions here to install swami. Some guy is working to get GTK2.0 integration at which point we'll probably see the package surface again.

We are interested in the little numbers in the Melodic section: (001-001 ... 001-004). The code is this: <bank>-<instrument>. That means that for this soundfont the 4 "sounds" are in bank 1 and are deposited as instrument 1-4. OK, so now we know the layout of the sound font. Now, when we play a midi file, we can map these to the appropriate instruments to get the sounds we want. So, how do we do that? We do it in timidity configuration files. My "harpsichord.cfg" file that is referenced by my timidity.cfg file looks like this:

dir /home/john/timidity/soundfonts/Piano/harpsichord

bank 0

6 %font Blanchet-440_ver.1.0.sf2 1 1
7 %font Blanchet-440_ver.1.0.sf2 1 2
8 %font Blanchet-440_ver.1.0.sf2 1 3
9 %font Blanchet-440_ver.1.0.sf2 1 4

Again, the "dir" command "activates" the directory that contains my Blanchet-400_ver.1.0.sf2 soundfont file so I can access it in my file by its base filename. The bank 0 is now specifying which instrument sounds we are going to provide for midi files that access bank 0 (which is most of them since bank 0 is the main bank).

<midi_instrument> %font <soundfont.sf2> <soundfont_bank> <soundfont_instrument>

midi_instrument: the program change found in the midi file. The General Midi (GM) typical mapping (note: timidity starts numbering at '0', so you need to subtract '1' from each of these to specify them in timidity).

%font: means this is a soundfont (patches don't require it), then .

soundfont_bank: the bank the instrument is found in your soundfont
soundfont_instrument: the instrument as found in your soundfont

So, here I've mapped the first harpsichord manual (bank 1, instrument 1) to instrument 6 ("harpsichord" in GM), the second harpsichord manual (bank 1, instrument 2) to instrument 7 ("clavinet"), the lute harpsichord sound (bank 1, instrument 3) to instrument 9 ("Celesta") and the sound with both harpsichords (bank 1, instrument 4) to instrument 10 ("Glockenspiel"). Now, a midi file that has a "program change" (instrument) specifying a harpsichord will access my first harpsichord manual and so on.

If a midi file is just one instrument, just match up the soundfont sound with the instrument specified in the midi file. If you have different midi tracks, you can go in and change the midi track to match up with those in your timidity file. This can be done in rosegarden (sudo aptitude install rosegarden) or many other midi editors (I write my own ruby programs based on midilib to modify instruments, volumes, pan, in my midi files but these (pan and volume) can also be specified in your timidity file (as long as each midi track accesses a different instrument). For example:

19 %font FluidR3GM.SF2 0 19 amp=140 pan=0 

Now we can fire up timidity on our midi file (here are some good ones). These each have different numbers of tracks, but each track is for "harpsichord" (which we've pointed to the first soundfont of the Blanchet file in harpsichord.cfg file):

timidity <your_midi>.mid
# or what I often will use:
timidity --verbose  <your_midi>.mid -EFreverb=3,40 -A150
# once you have it sounding like you want, you can record to a .wav file:
timidity <your_midi>.mid -Ow
# then you can convert to an mp3 with lame (install with: 'sudo aptitude install lame')
lame --preset medium <your_midi>.wav <your_midi>.mp3

Let me know if you have any questions/troubles and I'll try to update this post to answer them.

Friday, July 17, 2009

How to version control your projects with bazaar

So you have a project named 'supercool' that happens to sit in a directory named (what else) 'supercool'. Assuming you have bazaar installed on your client computer and the server, this is how you start a project under a centralized "lock-step" model. IMHO, this model works best for solo projects if you have a server available to you:

cd supercool # make sure you are at the top level directory of your project
bzr init # starts up version control in this directory (an independent branch right now)
bzr add # will recursively add files in your project
bzr ci -m 'initial commit' # makes a commit to your branch
# the next step assumes you have already made the directory /home//bzr on your server
# this step will create a centralized repository on your remote
bzr push sftp://<user>@myserver.domain.org/home/<user>/bzr/supercool
# now, we need to 'bind' our independent branch to the remote branch
# which transforms it into "centralized mode"
bzr bind sftp://<user>@myserver.domain.org/home/<user>/bzr/supercool

# to check out a fresh copy on a different computer
bzr co sftp://<user>@myserver.domain.org/home/<user>/bzr/supercool

So, now you can work on files in your project and have them versioned. Your daily work-flow will look like this:

# assuming you are in your project directory...
bzr up # update your repo with any changes in the centralized repo
## do some work...
bzr add <file1> <file2> # add any new files, etc.
bzr ci -m 'adding new files, changed some other ones'

That's it! The bazaar documentation is great, particularly the user guide.

Friday, June 26, 2009

Adding Music to a Blogger Blog using Playlist.com

There are basically two ways you can add a playlist.com music player to your blog on blogger blogs. The first that I tried was to use one of blogger's prepared gadgets. I found that these did not look very good. Instead, there is a better way.

1) Visit playlist.com and go to "Post My Playlist." Choose "Get the code for any other social network, blog or your own personal website >>". It is currently the last choice, choice "E". Follow their directions to get the code. Select and copy it.

2) Go to your blog and sign in. Go to "Customize", "Layout", "Page Elements", "Add a Gadget", "HTML/Javascript". Paste the code into the main field and you're set.

3) Sizing the player: View the blog and see how it looks. If you don't like the dimensions, you can change the element dimensions by going back and editing the html of the element. The height and width show up in several places in the code, so you'll want to change them all. For my blog, I currently have it set to 300px wide and 208px tall. I have copied the code from my blog, removing the "<" and ">" characters so that it wouldn't actually insert the player into this post. You can see that the easiest approach is really to do a ctrl+f to find all the numbers. Just be careful that they are really dimensions and not part of another number or for something else (for an example of a number you shouldn't change, see the blue 208).

div style="text-align: left; margin-left: auto; visibility:visible; margin-right: auto; width:300px;" object width="300" height="208" param value="http://www.profileplaylist.net/mc/mp3player_new.swf" name="movie"/ param value="never" name="allowscriptaccess"/ param value="transparent" name="wmode"/ param value="config=http%3A%2F%2Fwww.indimusic.us%2Fext%2Fpc%2Fconfig_black_shuffle.xml&mywidth=290&myheight=208&playlist_url=http%3A%2F%2Fwww.indimusic.us%2Floadplaylist.php%3Fplaylist%3D42390100%26t%3D1245208454&wid=os" name="flashvars"/ embed border="0" allowscriptaccess="never" flashvars="config=http%3A%2F%2Fwww.indimusic.us%2Fext%2Fpc%2Fconfig_black_shuffle.xml&mywidth=300&myheight=208&playlist_url=http://www.indimusic.us/loadplaylist.php?playlist=42390100&t=1245208454&wid=os" type="application/x-shockwave-flash" height="208" src="http://www.profileplaylist.net/mc/mp3player_new.swf" style="width:300px; visibility:visible; height:208px;" width="300" wmode="transparent" name="mp3player"/ /embed/object br/ a /a /div

To know what will look best in your blog, you might take some time to read through the html for your blog to find your sidebar width. If it is a percentage then you may just have to guess at the width until you get it how you want it. If it is set to a number of pixels (like 250px) then you can just change the width to 250px. That should usually give a good fit. If not, try a different width.

Wednesday, June 24, 2009

Weather-util alias for linux

With administrator rights open weatherrc (should be in etc/)

The file should have a bunch of entries that look similar to this. I am showing how I created an alias for DFW.

[DFW] #Alias name
City = Dallas Ft Worth #http://tinyurl.com/28pxfg (Find your city)
ID = KDFW #ID code, see note below on how to find it
St = TX #Enter your state's abbreviation

It is easiest to find your ID code by going to http://weather.noaa.gov/ and finding your Current Weather Conditions location. When you have found it look for the four letter identification, that is your ID.

Create your own aliases by adding to the weatherrc file.

Save the file and go to the terminal and type: weather DFW
If you want more information, tell it to be verbose: weather DFW -v
If you want the forecast: weather DFW -f

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.

Thursday, April 30, 2009

Battle for Wesnoth: Kid-Friendly

artwork from Battle for Wesnoth, modified by JTP


Skip intro

The Battle for Wesnoth--consistently ranked at the top of open-source games--is a really extraordinary strategy game that also happens to be free. On the surface it doesn't seem that special: it doesn't feature any stunning graphics and it is turn-based, so it is much more contemplative than action-packed. Why is it so great? Well, you really need to play it a while to understand, but the main things are:
  1. Very interesting strategy component - sort of feels like playing a higher-level Risk game or a slower turn-based Rise of Nations. To win you have to deal effectively with day/night, terrain, attack/defense, recruitment, character development, health etc. There are enough components to keep things interesting but not so many to be overwhelming.
  2. Engaging storylines - compelling single (and even some multi-user) campaigns.
  3. Character development - Characters can be developed somewhat (i.e, raise levels) which provides some familiarity (and hence attachment) to them but this is limited to only a few levels which prevents this aspect from overshadowing the game's strategy component.
  4. Good AI - the computer doesn't really make dumb moves, you either have to outsmart or overpower the enemy to win.
  5. Visually beautiful - I mentioned that the graphics are 2D, but even though they are simple, they are quite engaging. Much of the artwork is really great.
  6. Good music - in a classical-esque tradition.
  7. Free.
  8. Extendable - it isn't very difficult to create your own game or campaign.

Kid-friendly graphics

I have a lot of young boys who happen to really like this game. For a game set in a fantasy world completely realized with community contributed artwork, Wesnoth is remarkably kid-friendly. While there is nothing approaching pornography in it, there are a handful of portraits and units that are not attired as modestly as could be hoped. Most of the ones I've tidied up really didn't need it much, but since I was at it...

The beauty of open-source is that the software (in this case the images) can be modified to suit one's own tastes. I took liberty to touch up a few pictures, trimmed some others and wrote a script that will replace them in one click. The replacement artwork is rough around the edges, but it gets the job done (see my conglomerate image above).

How to run wesnoth-kid-friendly

This assumes you are on Windows (instructions are included in the zip file for other OS's):
  1. Install Battle for Wesnoth - ideally in the default location so my script can find it.
  2. Install the one-click ruby installer. (go the section "Ruby on Windows" and click on the "Ruby One-Click Installer link")
  3. Download my zip file. (this contains kid-friendly up artwork and a script to copy them into place).
  4. Unzip it.
  5. Click on wesnoth-kid-friendly.rb (NOTE: this writes over the old images. Of course, you can always reinstall it if you don't like what I've done)
By default, I scan typical linux and windows directories for a Battle for Wesnoth directory. If the script isn't finding your installation, you can run the program on the commandline with the path to the Wesnoth directory given as the only argument. Or email me with the path of your directory and I'll add it to the script.

Tuesday, April 28, 2009

Keyboard Shortcuts in Gnome, KDE, wmii, or whatever

Ubuntu Jaunty Jackelope put keyboard shortcuts in their proper place (disabling those in metacity and putting them in 'Keyboard Shortcuts'). However, when opening a gnome terminal from this shortcut, you have to explicitly tell it to start in your home directory or it will start in '/'

System->Preferences->KeyboardShortcuts  then [+Add]

gnome-terminal --geometry 80x52 --working-directory $HOME

I like to set up my keyboard shortcuts with a script since I like to use them on whatever computer I'm on. I did this before with gconftool2 and that worked fine, but now a person has to set them in a different location in a different way... which got me thinking that it would be nice to set keyboard shortcuts in a cross-desktop (KDE, Gnome, wmii, whatever) kind of way.

Solution: xbindkeys

sudo apt-get install xbindkeys

Make a file called '.xbindkeysrc' in your home directory with something like this in it:

control+alt + g
control+alt + n
"firefox -new-window http://gmail.com"
control+alt + e
control+alt + h
control+alt + f
"gnome-terminal --geometry 80x40"
control+alt + t
control+alt + m

now you can turn on the shortcuts with the simple command 'xbindkeys', but we'd really like for them to be turned on once when we login. Turns out cross-desktop startup is not very uniform but I think the proper way to do this (cross-desktop) is to do this:

Make sure you have a directory called '.config/autostart'. Then add a file to it called 'xbindkeys.desktop' with content along these lines:

[Desktop Entry]

This is what happens in Gnome when you add an entry in System->Preferences->StartupApplications.

Tuesday, April 14, 2009

Installing Storey's edge microarray software on Ubuntu

It takes a few steps to install this (Intrepid Ibex, Ubuntu 8.10), but here's how I got it working (we'll see if there are any bugs):

edge website

  1. Install R

  2. sudo aptitude install r-base

  3. Download and unpack the source file:

  4. linux src page
  5. Install impute

  6. Download the above link and install with something like this:
    sudo R CMD INSTALL packages/impute_1.0-5.tar.gz

  7. prepare the compiling environment

  8. sudo aptitude install g++-4.2 gfortran-4.2 tetex-base
    # (also might need tetex-extras ...)
    sudo rm /usr/bin/g++ # just removes the soft link
    sudo ln -s /usr/bin/g++4.2 /usr/bin/g++
    sudo rm /bin/sh # just a link to /bin/dash
    sudo ln -s /bin/bash /bin/sh

  9. Compile the sucker

  10. cd src ; make ; make install

    The make install command just copies the .so files up a directory
  11. Run the software

  12. R

    Then from within R started at the base of the package:

  13. Restore the original environment

  14. sudo rm /usr/bin/g++
    sudo ln -s /usr/bin/g++4.3 /usr/bin/g++
    sudo rm /bin/sh
    sudo ln -s /bin/dash /bin/sh

Parametric and non-parametric t-testing

If your data are distributed normally, the t-test can help you determine if the means of your two samples are greater than or less than each other (one-tailed) or just plain different from each other (two-tailed). These examples are for paired samples, to make them not paired just delete the "paired=TRUE" statement altogether, default is unpaired.

We'll use the same data throughout:
x <- c(1.83, 0.50, 1.62, 2.48, 1.68, 1.88, 1.55, 3.06, 1.30)
y <- c(0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29)

When using your own data you just need them in vectors (as shown).



What if your data are not normal? The non-parametric Wilcoxon test will do the trick. The Wilcoxon rank-sum test is for independent samples (unpaired). The Wilcoxon signed rank test is for paired samples.

wilcox.test(x, y, paired = TRUE)

Who is R?

After several years of using R to do various tasks from simple t-tests to much larger data sets I think I finally understand who R is.

R is like the computers of yesteryear, it does what you tell it, and only what you tell it, period. If you want more than the minimal amount of output, you have to ask for it. But it also has a bit of an attitude, for example, instead of outputting the type 3 sums of squares in ANOVA like virtually every other statistical package, it outputs the type 1 sums of squares by default. Why you might ask? The reason is because they want you to first think about what type of sums of squares you want, so by default they give you the one that isn't the most commonly used one. Hence R has a steep learning curve, which after several years I am still trying to surmount.

Enough talk, time for some code in the next post.

Saturday, April 11, 2009

Instant switching: compiz (gtk), emerald, metacity

In various places these are incorrectly listed. At least as of Intrepid Ibex, here's how to switch between window managers... still trying to figure this out...
metacity --replace
emerald --replace
compiz-decorator --replace
compiz # to start things up for compiz

Oh, but when I try it out I'm getting some problems. In theory ... Just put each of these lines in a custom application launcher on your panel (and maybe put those in a single drawer)

Thursday, March 26, 2009

ocaml batteries on Ubuntu

OCaml is a functional programming language. I'm trying to learn it right now, but it clearly has a steep learning curve, especially if you aren't familiar with functional programming languages. It does seem impressive in many ways, but we'll see, eh?

Anyway, the standard library seems a little sparse, so I am trying to install 'batteries'. Turns out it wants some dependencies to build and they aren't entirely straightforward. Here's how to get it building:

sudo aptitude install libcamomile-ocaml-dev libzip-ocaml-dev libtype-conv-camlp4-dev
libsexplib-ocaml-dev libbin-prot-camlp4-dev libocamlnet-ocaml-dev

(do we need libmagic-ocaml-dev ??)
This is super weird, you have to configure the program as super user because it wants to make a directory for batteries in /usr/local. Anyway, here's the install

sudo ./configure
sudo make all opt install install-doc

And it does take forever to make the documentation (maybe 5 minutes to install on my computer).

Friday, March 6, 2009

how to set up your own git repository with only a server, ssh, and git

This assumes you have ssh access to a server somewhere which you want to use as a sort of centralized repository and that server and your local machine have git on them. Don't tell anyone I used centralized and git in the same sentence, but centralized makes a lot of sense to me for lots of things, especially my own projects.

I'll do it the long way first and then with a tiny bit of bash scripting:

# ssh into your server
ssh jtprince@yourserver.domain.edu
# on remote machine:
mkdir git
mkdir git/project1.git && cd git/project1.git
git --bare init

# on local machine
mkdir project1 && cd project1  # if you don't already have a project
# make a commit (you need at least one commit)
git init
echo "some text" > file.txt
git add .
git commit -m 'init commit'

# now we will push it to the server
git push ssh://jtprince@yourserver.domain.edu/home/jtprince/git/project1.git master

# we still need to link our git folder with the server
git remote add origin ssh://jtprince@yourserver.domain.edu/home/jtprince/git/project1.git
git config branch.master.remote origin
git config branch.master.merge refs/heads/master

Now for the BASH scripting I promised. This is basically the same thing but maybe a little easier to copy and paste once you set up your variables:


# set up the remote git repo in one command:
ssh $SERVER "mkdir git/${PROJ}.git; cd git/${PROJ}.git; git --bare init"

# (inside your project directory... with files/dirs already present):
git init ; git add . ; git commit -m 'init commit'; git push $PROJ_URL master ; git remote add origin $PROJ_URL ; git config branch.master.remote origin ; git config branch.master.merge refs/heads/master

And my rant...

At least in the ruby and linux developer community, Git seems to be quite hip right now. I personally think bazaar wipes git all over the floor, but due to server circumstances beyond my control I need to version control my files with git.

While the above operation is CLEARLY and SUCCINCTLY documented in the main bazaar docs, I've had to piece this together myself for git. Now, I suppose if I had actually read and digested the volumes of arcane documentation, switches, and nuances of git, I wouldn't be griping right now. That said, projects like 'eg' can make it easier and I'm sure the things people want to do with a vcs will become documented soon enough in git... the beauties of open source.

Tuesday, February 17, 2009

Gnome Do Dominates

I am always trying to do things faster, and as we all know, using the keyboard is often faster than the mouse. Gnome Do, which you can install from synaptic is intuitive and lets you really fly. Try it out.

Friday, February 13, 2009

Can't mount external hard drive

Some people have suggested "forcing" your external hard drive to mount. This is a bad idea as you can lose your data. Simply plug your external hard drive into a Windows system and then safely remove the external hard drive; if you just unplug it without safely removing it, Ubuntu won't let you mount it without forcing it to.

Tuesday, January 13, 2009

Aggregate in R

For data that needs to be collapsed, the aggregate() function works great. For example:

If you need to collapse these so you only have one row per GLEAN, and have the Female and Male columns be the average of the collapsed rows, aggregate() can do this in one line:

collapsed_data<-aggregate(x=original_data, by=file_with_GLEAN_names_only, FUN=mean)

I used this to find the average expression levels of genes from a table that had the expression levels of each exon. Since some genes had one exon while others had many exons, aggregate was perfect for this situation. It did take a few minutes to compute, but I had over 57,000 rows and 8 columns, so that's understandable.

Virtualization with Virtual Box in Ubuntu

I copied some material from these links in doing this (there are one or two errors in them that I correct here):
  1. make sure you have the 'build-essential' package installed:
    sudo apt-get install build-essential
  2. Download your version of virtual box (probably i386 unless you have a 64 bit processor) and install it

    After download, right click the package and install with the GDeb package manager

  3. Add your user to the vboxusers group:
    sudo adduser $USER vboxusers

  4. Follow the Setup VirtualBox USB Support section here for USB support
    I did both of the things recommended. Note that the last step should read:
    sudo /etc/init.d/mountkernfs.sh start

  5. Install Guest Addons and turn on seamless mode
    after firing up the virtual OS, go to the 'Devices' window on the top and 'Install Guest Additions'
  6. Set up shared directories following this.

Wednesday, January 7, 2009

autotest with specs in a normal ruby library

Put this in a '.autotest' file in your project's base directory:

# -*- ruby -*-

# in .autotest file:

Autotest.add_hook :initialize do |at|

Autotest.add_hook :initialize do |at|
at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
## for both specs and tests: