getwd() # retrieve your current working directory
setwd("some path on your computer") # set your working directory using your personal file paths
This is a brief introduction to setting up your workflow, downloading the datasets and associated packages.
I recommend working through this introduction if you need a refresher on R and R Studio.
Working directory
This quarto website is designed to contain all of the code and output to complete the learning tasks.
The project folder containing all .qmd files required for this tutorial should be downloaded and run on your own computer to complete the activity.
To set-up your workflow correctly, please…
- Ensure that you have a recent version of ‘R’ downloaded from r-project.org. This workshop was built with R version 4.4.1 (Race for Your Life).
- Download R Studio.
- Create a workshop folder in your local field system.
- Download all .qmd files from the workshop github and save them to your workshop folder.
- Set your working directory to the workshop folder.
Packages
The required packages and versions utilised in this workshop should be located in the project renv
. Without version control, they can also be installed and located using the following code.
## install packages
#install.packages("survey")
#install.packages("haven")
#install.packages("labelled")
#install.packages("dplyr")
#install.packages("questionr")
#install.packages("gtsummary")
#install.packages("ggthemes")
#install.packages("RColorBrewer")
#install.packages("jtools")
#install.packages("hexbin")
#install.packages("quantreg")
## load packages into your global environment
library(survey) # handling survey data with complex sampling design
library(haven) # for reading in non-native data formats (e.g. Stata's .dta files)
library(labelled) # working with labelled data
library(dplyr) # data manipulation
library(ggplot2) # data visualisation
library(questionr) # data visualisation with survey design objects
library(gtsummary) # nice publication ready summary tables
library(ggthemes) # change theme of ggplot objects
library(RColorBrewer) # for color schemes
library(jtools) # visualising regression results
library(hexbin) # assist with plotting graphics
library(quantreg) # supports boxplot functions for ggsurvey
Data
This workshop utilises data from two repositories: the UK Data Service (UKDS) and the European Social Survey (ESS). Both datasets are open access but require that you make an account with the associated repositories.
We will load two datasets that feature different sampling designs and information in the data documentation to practice loading, reading about the methodology, and encoding this information in the survey design object.
Dataset 1: The Children’s Worlds Survey
Step 1: Register with the UKDS
- Navigate to the UKDS login channel.
- If you are a member of a UK research organisation, login through your institution. If not, you will need to request a username and then sign-in here.
Step 2: Download the dataset
- Go to the data browser and search for the study identifier “SN 7910” for the Children’s Worlds Survey: England, 2013-2014
- Ensure the doi matches:
10.5255/UKDA-SN-7910-1
- Press “Access data” and download the Stata .dta format.
- Unzip the folder and place in your workshop folder.