Structural Geology @ Hamilton College

Statistical analysis scripts and code

I do all of my structural analysis of field data using the R programing language, and all of my microstructural (EBSD) analysis using the MTEX toolbox in Matlab. If you are interested in getting started doing the same, then this is the page for you!

This page is dedicated to providing set-up documentation for analysis scripts that have been included as part of published work. For permanent repositories of published and some unpublished scripts, please visit my GitHub page. Please email me at nmrobert@hamilton.edu if any scripts do not work properly after following the directions below. Things can happen...for example, R packages are often updated or sometimes get archived, and as a result scripts may need periodic updating

Update: On June 25, 2019 I made a few corrections to the Utility of statistics in structural geology scripts, including no longer loading a defunct library ('FRB').

For published work, I include all the files necessary to reproduce my statistical analysis on this page.

From The utility of statistical analysis in structural geology (Roberts et al., 2018)

Download the manuscript and the figures. download the published pdf here.

This paper analyzes three datasets: two from the West Mountain area of the western Idaho shear zone, and one from the Orofino area of the western Idaho shear zone, locally the Ahsahka shear zone. The two datasets from West Mountain are a foliation dataset and a dataset of foliation-lineation pairs. The data from Orofino are foliation-lineation pairs.

Note: The scripts in this project have been written for specific static versions of the geologyGeometry library, for which download links are given. If you would rather download the most recent version of geologyGeometry (which may not be backwards-compatible with all statistical analyses), visit Joshua Davis's website.

  1. If you have not already downloaded R and RStudio and set it up for using geologyGeometry, then follow the instructions to do so at the bottom of this page.

  2. Dowload geologyGeometry June 2017 version. This linked version already contains the datasets and statistical analyses from Roberts et al. (2018).

  3. Drag the 20170620geologyGeometry folder to your desktop. Note for Windows users: When Windows unzips a .zip file, it creates a folder with the .zip name. Open this folder, and you will fine the 20170620geologyGeometry folder within. Drag 20170620geologyGeometry to the desktop.

  4. The two statistical analysis scripts are titled JSG_StatisticalAnalysis_Orofino.r, and JSG_statisticalAnalysis_WestMountain.r, both located in the geologyGeometry folder. Open them in RStudio.

  5. At the top of each one, change setwd('~Desktop/20170620geologyGeometry') to reflect the true path to your geologyGeometry folder. You should not need to change this if you are using a Mac. If you are using Windows, the proper path format is commented (anything that has a '#' in front of it is 'commented', meaning it won't run). Fill in your user name, uncomment the line, and run it.

  6. Run each file line by line using "Run" button at the top of the window. Enjoy!

  7. Strongly encouraged: In the 20170620geologyGeometry folder, you will find many tutorial subdirectories. Each of these subdirectories contain well-commented tutorial scripts by Joshua Davis that guide you through the basics of statistical analysis. If you are new to coding, I recommend starting with the tutorial files in tutorialsR, followed by tutorialsDirections and tutorialsOrientations.

R/RStudio Setup Instructions before using geologyGeometry:

  1. Dowload R for your system.
    • Choose a "mirror site" that hosts the software, prefereably near your geographical location, for speed.
    • On the mirror site, click to download a "precompiled binary distribution" of R for your operating system.
    • Once the download is complete, run the installer program and follow its instructions.

  2. Download and install RStudio, a nice user interface for using R.

  3. If you are installing on a Mac computer, download and install XQuartz. (You will need to log out and log back in after installing to activate it). XQuartz is a unix windowing system that geologyGeometry uses for interactive plots.

  4. Now, launch RStudio. It will open large window consisting of several "panes". Probably the Console pane is in the lower left corner of the window. Copy and paste (or retype) the following three lines of code into the Console pane, and then press Return to execute them. This step only needs to be done the first time you use R/RStudio. It will permenantly install some R packages that geologyGeometry uses.
    • install.packages(c("rgl", "fields", "MASS"))
    • install.packages(c("ICSNP", "expm", "FRB"))
    • install.packages(c("Directional", "pracma"))

    These commands should cause a flurry of activity. If you are notified that a source version is newer than a binary version, and asked whether to download the source version (y/n), enter n. If you see warnings about how some package was built with an earlier version of R, then ignore them. To check that each package installed correctly, copy each of the following lines into the console.
    • library("rgl")
    • library("fields")
    • library("MASS")
    • library("ICSNP")
    • library("expm")
    • library("FRB")
    • library("Directional")
    • library("pracma")

    You are now all set up to use the geologyGeometry tools.