Monthly Archives: July 2013

A call for help: (open) science tools

As I announced in my first blog post: I am working on creating a list of all kinds of science services on the web, in the hopes of creating a low-threshold open science workflow. I try to stay on top of all kinds of tools, but I find new ones each day—creating the feeling that I am not as encompassing as I would like to be.

To improve this, I would like to request the (scientific) community to help and check out the spreadsheet in which I show all the services I have found thus far. You can find it here, and it can be freely edited. If you think you have a service that should be on the list, please put it on there. If you are not sure, put it on there and I will see its applicability. Better to have too many input than too little at the moment. If its initial use for research is unclear, please put something in the notes so I know how it might be a valuable tool, even though it is initially not aimed towards research (e.g. Github). Feel free to contact me on twitter (@chartgerink) if you have any questions.

Please note that, if signed in to your Google account, your name will appear on the revision history. If you prefer this not to happen, please log out of your Google account or open a private session in your browser (often Ctrl+Shift+N).

Merging Mendeley and Zotero bib files (Windows)

UPDATE: @mrgunn informed me of a native function in Mendeley to merge the libraries, making the steps below redundant. The setup is trivial: in Mendely, go to Tools–>Options–>Zotero/CiteUlike tab. Open the SQL database from Zotero and it will automatically import the data (including attached PDFs). If you do not know where to find your Zotero library, go to (within Zotero standalone) to Tools–>Options–>Advanced–>Files and Folders–>Show data directory.

The original post can be found below.

##############################################################################

I recently started using Zotero next to Mendeley for my reference management, but I was sort of agitated about maintaining two libraries in two different programs. I like Zotero’s quicksave too much and Mendeley’s auto import too much to give up either one, so I decided to figure out how to make it easy for me to cite from both libraries when writing up papers in LaTeX. Below I will outline how to make one full library file on a semi-automatic basis (i.e. requires only one key press to update your library).

Step 1—Set Mendeley and Zotero to automatically sync your references into a BibTeX file
Mendeley has a default option to sync the library into a BibTeX file. This option can be found under the menu option Tools–>Options–>BibTeX. I recommend syncing your entire library into one file and not per collection, otherwise you will have to update the script (explained in step 2) everytime you create a new collection.
For Zotero, an add-on needs to be installed, which can be found here. This is a Zotero to BibTeX plugin developed by Robin Wilson. Installing it is easy (just follow the steps on his website) and it will allow you to sync your Zotero library into the folder of your choosing. I recommend syncing it into the same folder as the Mendeley file.

Step 2—Make a script for merging the .bib files
This step sounds much more difficult than it is. We need only two lines of code to make the script run. The first line changes the working directory (you will need to fit this to the folder you sync the Mendeley- and Zotero .bib files to) and the second creates the merged .bib file. All you need to do is open notepad and type in:

cd C:\Users\Chris Hartgerink\Dropbox\Bibs\
copy library.bib+Zotero.bib fulllib.bib

Note that you will have to check whether the path file and file names correspond to your personal settings. You subsequently save this file as merge.bat (or any other filename, but with extension .bat), and run it to merge your libraries.

Step 3—Use AutoHotKey to create a keyboard shortcut for running the script
This step is optional, but highly recommended. AutoHotKey is a program where you can write map keyboard shortcuts to virtually any action you want. Installing AutoHotKey is a breeze, and the only thing you need to do is create a .ahk file that contains your key mappings. I personally keep one file where I maintain ‘all’ the code (use only 30 lines) and automatically run this at startup (see here for a how-to). I mapped the script to the control + F7 key, resulting in the ‘code':

!F7::Run,merge.bat,C:\Users\Chris\Dropbox\Bibs\

The ! stands for the control key (^ stands for alt, see here for an introductory tutorial). Everytime I use this keyboard shortcut the merge script runs and updates my library BibTeX file.

My apologies for the Mac and Linux users who I leave in the dark with this tutorial.

 

R: Quickly installing and opening multiple packages

Often when doing analyses in R you need to install and load many packages, and it can be tedious to type \texttt{install.packages()} and \texttt{library()} a thousand times. The code below illustrates an efficient way of installing and opening up many packages instantly. You only need to change vector x and possibly comment out the second line of code if you have already installed the packages. Efficiency for installing packages could be improved by not reinstalling packages, but I have not checked into this yet.

#Insert packages you want to install and open in vector x
x<-c("boa","R2WinBUGS")
lapply(x,install.packages(x),character.only=T)
lapply(x,library,character.only=T)

Awkward default for the function t.test in R

I was checking the \texttt{t.test} function in R, and found out that by default it assumes unequal variances. This de facto implies that the assumption is violated, unless specified not to be the case. The main problem that this causes is that even when there is independence between groups, the test will correct for the correlation, even if it is tiny. This causes the degrees of freedom to deviate from round numbers, and might cause confusion for readers if copied directly into a paper (I have tried some things and it does not seem to affect the results).

To correct for this, the default argument \texttt{var.equal=F} should be set to true, i.e. \texttt{var.equal=T}. The code below shows the difference in degrees of freedom between the two (directly pastable into R).

#Check that t.test function is correct for Independent samples t.test for two cases
x1<-rnorm(100,5,.5);x2<-rnorm(100,6,.5);cor(x1,x2)
t1<-t.test(x1,x2,paired=F,var.equal=T,digits=6) #Beware that default is var.equal=F 
t2<-t.test(x1,x2,paired=F,var.equal=F,digits=6)
#Compare degrees of freedom between var.equal=T and var.equal=F
t1[2];t2[2]