Multiple comparison test for non-parametric data

“Which packages and tests can you use in R to examine the significant differences between groups within a Kruskall-Wallace non-parametric analysis of variance?”

Here is a stackoverflow thread on this, and below is an example using kruskalmc from pgirmess:

# make a test data set using random numbers
set.seed(100) # makes random numbers repeatable
dat <- data.frame(class = rep(c(1,2,3,4,5), each = 5) # factor
, value = runif(25, 2.5, 7.5) # random number
)

# make one group different
dat$value[1:5] <- dat$value[1:5] + 5

kt <- kruskal.test(value ~ class, dat) # Kruskal Wallis test
print(kt) # show Kruskal Wallis result

# for the multiple comparison test we can use the package pgirmess
library(pgirmess) # load library (install if necessary)
kmc <- kruskalmc(value ~ class, dat, probs = 0.05) # multiple-comparison test
print(kmc) # gives row names as comparisons and TRUE or FALSE

# sometimes you want to look for "homogenous groups"
# and give each group a code (like a letter)
library(multcompView) # load library (install if necessary)
test <- kmc$dif.com$difference # select logical vector
names(test) <- row.names(kmc$dif.com)# add comparison names
# create a list with "homogenous groups" coded by letter
let <- multcompLetters(test, compare="<", threshold=0.05,
Letters=c(letters, LETTERS, "."),
reversed = FALSE)

# this result could be shown on a box plot
boxplot(value ~ class, dat
,xlab = "Class", ylab = "Value"
, ylim = c(0,max(dat$value,na.rm=T)*1.5)
, notch = F, pch = ".")
mtext(side=3,text=let$Letters,at=1:length(let$Letters),cex=0.8) # letters at top

KWMC_boxplot_example

Posted in R examples | Tagged , , , , | Leave a comment

Bibliographies with Zotero, JabRef and BibTeX

Getting the bibliography right for a scientific article can be a frustrating process, particularly if at some point you have to change the format for a different journal. There are many great tools out there to help with the collection, management and typesetting of bibliographies; here is my work flow using a combination of Zotero, JabRef and BibTeX

Citation collection and management

Now days I tend get all of my citations via online searches (such as Google Scholar) and like to have a PDF copy of the article. I also work on various computers (with different operating systems) and like to have a single bibliographic database, with the citations + PDF downloaded on different systems all in one place (i.e., syncing). There are many options, but I find the open-source software Zotero (available as Firefox/Chrome extension or standalone) does this job very well. It makes it very easy to import citations directly from searches, it can automatically download PDFs and syncing on multiple systems is easy (although for syncing PDFs extra storage is necessary, and can be setup using either the Zotero service or via a WebDAV compatible storage service, such as CloudMe). Note when setting up Zotero make sure you place your storage folder in an easily accessible place rather than the default within the Firefox folders!

Once the citations are in Zotero it is easy to make corrections to fields, include notes, attach files and organize into folders. Zotero can be used as your full reference manager solution allowing importing of formatted citations into MS Word and libreoffice documents, however here we will be using LaTeX for document preparation. To do this we will use the handy function “export collection in BibTeX format”.

Cleaning and standardizing BibTeX files

Now I have a text file (.BIB) with a selection of citations that maybe included in my article, this is a “working” list that will change during the article preparation, adding new citations and maybe deleting or adjusting others. Once the article is ready, this list needs to be cleaned up  by fixing the citation information and removing unused citations. For this task I found JabRef very handy.

An example work-flow:

  1. Compile the finished article with the “working” .bib file
  2. Open up JabRef and open the article .bib file
  3. Goto Tools>New sub database based on aux file, click Generate, review and fix problems (such as missing entries), click OK and save new tab in the folder with .tex files (remember to use same name or change name in .tex file)
  4. Fix journal abbreviations: select all entries (cmd+a), goto Tools>Abbreviate journals ISO. Hint: Any entries that are not on the default list can be added in Options>Manage journal abbreviations
  5. Checking citations for mistakes, at present, is a job that just has to be done by hand. Fixing LaTeX formatting problems is a bit annoying, but I guess there are probably some efficient solutions for this (I shall add them as I discover them!).

Journal specific formatting of citations within an article

Details about using citations within LaTeX can be found elsewhere, but essentially to get the format right in your final document you need a citation style file (.BST). These can sometimes be found on the journals site (such as PLOSOne) or via searching the web (such as here) or maybe already included in your LaTeX distribution. Simply place the BST file in the same directory as your article and update your .TEX file with the name of the style. if you need to change style, simply replace the BST file and update your TEX document.

Posted in Research tools | Tagged , , , , | Leave a comment