# Installing R in Linux

This guide is intended to faciliate the installation of up-to-date R packages for users new to either R or Linux. Unlike Windows binaries or Mac packages, Linux software is often distributed as source-code and then compiled by package maintainers. The use of package managers has many advantages that I won’t discuss here (see Wikipedia).
More importantly, the difference can be initially intimidating.
However, once the user gets used to using package managers such as apt or yum to install software, I’m confident they’ll appreciate their ease of use.

These instructions are organized by system type.

## Debian-based Distributions

### Ubuntu

Full installation instructions for Ubuntu can be found here. Luckily, CRAN mirrors have compiled binaries of R which can be installed using the apt-get package manager. To accomplish this, we’ll first add the CRAN repo for Ubuntu packages to /etc/apt/sources.list. If you prefer to manually edit the sources.list file, you can do so by issuing the following in the terminal:

# Faster SSCC Access Using Bash

I use SSH regularly to login remotely to servers for experiments and data analysis. For instance, Northwestern’s Social Sciences Computing Cluster is available with an SSH remote login and using X11 forwarding, I can access RStudio and run analyses that require more memory than my office iMac has. However, logging into the SSCC over SSH isn’t as quick and launching a program in Spotlight.

While browsing a friend’s .bashrc on Github, I realized I could use a simple Bash function to speed things up. Copy and paste the following into Terminal:

After you restart Terminal.app, you can launch RStudio remotely by typing Rsscc, or whatever you renamed my function to. In principle, you could also create a simple menu for choosing among multiple servers or programs using a bit of read and case.

Note: This works best if you’re using an up-to-date version of X11, such as XQuartz and are accessing the SSCC using Ethernet.

# Analyzing Qualtrics Data in R Using Github Packages

Qualtrics is an online survey platform similar to SurveyMonkey that is used by researchers to collect data. Until recently, one had to manually download the data in either SPSS or .csv format, making ongoing data analysis difficult to check whether the trend of the incoming data supports the hypothesis.

Jason Bryer has recently developed an R package published to Github for downloading data from Qualtrics within R using the Qualtrics API (see his Github repo). Using this package, you can integrate your Qualtrics data with other experimental data collected in the lab and, by running an Rscript as a cronjob, get daily updates for your analyses in R. I’ll demonstrate the use of this package below.

# Graphing Error Bars for Repeated-Measures Variables With Ggplot2

When presenting data, confidence intervals and error bars let the audience know the amount of uncertainty in the data, and see how much of the variance is explained by the reported effect of an experiment. While this is straightforward for between-subject variables, it’s less clear for mixed- and repeated-measures designs.

Consider the following. When running an ANOVA, the test accounts for three sources of variance: 1) the fixed effect of the condition, 2) the ability of the participants, and 3) the random error, as data = model + error. Plotting the repeated-measures without taking the different sources of variance into consideration would result in overlapping error bars that include between-subject variability, confusing the presentation’s audience. While the ANOVA partials out the differences between the participants and allow you to assess the effect of the repeated-measure, computing a regular confidence interval by multiplying the standard error and the F-statistic doesn’t work in this way.

Winston Chang has developed a set of R functions based on Morey (2008) and Cousineau (2005) on his wiki that help deal with this problem, where the sample variance is computed for the normalized data, and then multiplied by the sample variances in each condition by M(M-1), where M is the number of within-subject conditions.

See his wiki here for more info.

# Using Figures Within Tables in LaTeX

By using LaTeX to author APA manuscripts, researchers can address many problems associated with formatting their results into tables and figures. For example, ANOVA tables can be readily generated using the xtable package in R, and graphs from ggplot2 can be rendered within the manuscript using Sweave (see Wikipedia). However, more complicated layouts can be difficult to achieve.
In order to make test items or stimuli easier to understand, researchers occasionally organize examples in a table or figure. Using the standard \table command in LaTeX, it’s possible to include figures in an individual table cell without breaking the APA6.cls package. For example: