2 Mediation & Confounding

This section of the practical will take you through the initial analyses a social epidemiologist might take to determine if socioeconomic position is associated with HIV risk in young Tanzanian women. The goal of this practical is not to focus on the R or Stata code, but instead to understand conceptually what is happening and be able to interpret the output critically.

This initial session will consolidate your understanding of mediation and confounding. In this session we will seek to get to know the data, calculate some basic prevalences, describe the association between educational attainment and HIV, and adjust for a potential confounder.

There is no explicit paper associated with this practical, but some papers of interest are:

In this practical, we will use data from the AIDS indicator survey carried out in Tanzania in 2007. The data includes only adolescent girls and young women aged 15-24 years of age who were residing in rural areas. The dataset contains one record for each of the 2762 young women included in the survey with information on their HIV serostatus.

Step 1 is to ensure that your R Notebook and your data are in the correct place. As long as the R Notebook and the dataset socepi_tz.dta (available from U:/Download/Teach/Social Epidemiology) are in the same place, the code below will work.

In R, not every tool we need for analysis is automatically included. We load a number of user-built libraries to make our lives easier. To run code in RStudio, you place your cursor on the line and press Ctrl-Enter, or if you want to run the whole chunk, mouse click the green triangle at the top right corner of the code chunk (in grey).

Once you have loaded in the libraries, we are going to read in the data. You should see it appear in the ‘Environment’ pane in the top right hand corner of RStudio as a dataset called ‘tz’. You can click on the dataset in the Environment pane and it will open in a new tab. Browse through the data now.

#--- Read in data
tz <- read.dta("E:/LSHTM/Teaching/socepi/socepi_tz.dta", convert.factors = T)