R Scripts


Some R Scripts for Data Processing

Also see https://sites.google.com/view/racognition/

Full Data Plotter 

(Built with R / GGPLOT2)

This script can be used even by those with only minimal knowledge of R. If you can install R and run R code, you can use this script to make a plot that conveys central tendency and variability along with full distributions of the data. 

As illustrated on this page, you can have the means be the principal elements, with error bars indicating either standard errors or 95% CIs. Alternatively, you can choose to have the medians be the principal elements, with error bars indicating the 25th and 75th percentiles.

Just enter the appropriate variable names and variable levels from your data file (along with a few other bits of information). 

Note: Your data file needs to be in "long" format if it includes repeated-measures data. That is, the factor levels must vary across rows, rather than across columns.  (R scripts for converting between "long" and "wide" format are available further down on this page.)  

Here is the data plotter script (it's a .R file that can be opened by R Studio) and here is an example data file to be used with the script. One way to proceed is: (a) have R Studio already installed, (b) put the script file and the data  file in the same directory (the same folder) on your computer, (c) double-click the script file to open it in R Studio, (d) follow the instructions that are inside the script. 

Note. The figure shows means surrounded by standard-error error-bars. The accompanying black dots show the medians. The contoured regions and scattered circles show the distributions.

Scripts for Restructuring a Data Set 

Wide-to-Long Data Restructurer

Long-to-Wide Data Restructurer


An R Script for Horizontally Aligning Data

Function for Horizontally Aligning Data

Bootstrap Analysis

Bootsy 1.0

Bootstrap (nonparametric) analysis for comparing a median to zero, for comparing two medians, for computing a Delta D statistic that compares the difference between the difference between two medians (as a non-parametric alternative to a 2-by-2 ANOVA interaction), and for computing an eight-group Double Delta D statistic. 

Bootsy is based on R's bcaboot package. See Efron, B., & Narasimhan, B. (2020). The automatic construction of bootstrap confidence intervals. Journal of Computational and Graphical Statistics, 29(3), 608-619. https://doi.org/10.1080/10618600.2020.1714633


Adjusting a Set of P Values to Correct For Multiple Testing

This is not a script, per se. It's just an example of how to use R's p.adjust function to correct a set of p values to avoid Type I error inflation due to multiple testing.


# This code computes the Holm-corrected p values for a vector of 

# uncorrected p values. (Options besides "holm" are: 

# "hochberg", "hommel", "bonferroni", "BH", "BY", and "fdr".)


p.adjust(c(.027, .141, .018, .053), "holm")  


# output: [1] 0.081 0.141 0.072 0.106

Essential Aspects of Adding New Computed Variables to an R Data Frame

Computing New Variables in an R Data Frame

Importing a Data Set from a CSV File in Posit Cloud's RStudio

In Posit Cloud RStudio's lower-right menu, select the up arrow, then CHOOSE FILE.

In Posit Cloud RStudio's upper-left menu, select FILE, then IMPORT DATASET.

Exporting a Data Set from R into a CSV File

At the end of the code, include the following command (where data happens to be the name of the data frame you want to export):

write.csv(data,"MyExportedDataFile.csv", row.names = FALSE)