Instructions

Author

Murray Logan

Published

September 15, 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
set.seed(123)
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  4.439524
2  2 High  7.769823
3  3 High 12.558708
4  4 High 14.070508
5  5 High 17.129288
6  1  Low  7.715065
7  2  Low  9.460916
8  3  Low 10.734939
9  4  Low 14.313147
10 5  Low 17.554338

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/SUYRs_documents/SUYRs_documents/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.