ReefCloud R/Statistics resources

Author

Murray Logan

Published

March 31, 2024

1 Purpose

This tutorial series should be considered reference and background materials in support of preparation for more advanced statistical analyses with R. The topics covered progress from introductory and foundational through to more advanced and as such, the tutorials are intended to be consumed and worked through largely in the order laid out in the sidebar menu to the left.

2 Format of tutorials

2.1 R code

Throughout the tutorials, R code snippets will be presented in a block such as:

## construct variables
x <- rep(1:5, times = 2)
g <- gl(n = 2, k = 5, labels = c('High', 'Low'))
y <- 2 + (3 * x) + (as.numeric(g) - 1) + rnorm(10, mean = 0, sd = 1)
## compile into a data frame
dat <- data.frame(x, g, y)
## print out data frame
dat
   x    g         y
1  1 High  6.159279
2  2 High  9.072112
3  3 High 10.225115
4  4 High 12.991526
5  5 High 16.641695
6  1  Low  6.770141
7  2  Low  8.875500
8  3  Low 12.071153
9  4  Low 14.714911
10 5  Low 17.774427

This format is partially reminiscent of the layout of code editors, albeit with a very opinionated color scheme.

  • the R code appears as the text over the faint yellow background.
  • any output appears below the code (white background) and in red font
  • the light gray numbers in the left hand gutter represent the line numbers. These can be useful when trying to draw attention to a particular line of code
  • the light gray text in the R code block beginning with two hash symbols ‘##’ are comments
  • in the upper right hand corner there is a clipboard symbol. Clicking on this symbol will copy the code to the clipboard to help you transfer the code to your own R session.

Occasionally (and particularly within tables) code snippets may alternatively be presented without the line number gutter. In such cases, there tends to only be a single line of code and there are substantial space savings if the gutter is removed.

x <- rep(1:5, times = 2)

2.2 Bash (shell) code

Bash is a command-line shell that gives you access and control over your computer’s operating system. Whilst the majority of the tutorials in this series are focused on R, there are a couple of tutorials on other supporting topics (like version control) that might be interfaced via a shell (commands entered on a terminal). Furthermore, some software installation and/or configuration instructions might be in the form of shell commands.

Such commands are presented as:

pwd
/home/runner/work/workshops/workshops/tut

2.3 Plain text

The contents of plain text files will similarly be presented either as:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Maecenas sed metus congue risus sagittis viverra. Etiam 
hendrerit orci arcu, et vehicula libero vulputate nec. 
Aliquam placerat lacinia ex sit amet varius. Suspendisse 
potenti. Nam tristique fringilla lacus id tincidunt. Donec 
quis turpis tempus leo pharetra malesuada. Vivamus consequat 
a quam nec vestibulum.

or when necessary to save space:

Lorem ipsum dolor sit amet, consectetur adipiscing elit.