PC Labs for SO5041: Week 11

Table of Contents

Week 11 Lab: Correlation

Correlation

The following data file contains six pairs of variables, X1 and Y1, X2 and Y2 etc.

library(foreign)
pairs <- read.dta("https://teaching.sociology.ul.ie/so5041/correl.dta")

First, graph all six pairs in scatterplots. What sort of association do you see in each case (positive, negative, none, strong, weak)? Make a guess what the value of the correlation coefficient might be (write it down).

For each graph, get the correlation coefficient: e.g., cor(pairs$x1, pairs$y1). How do the reported correlation coefficients correspond with those you guessed?

Correlations with real data

With the following data file, ocorr <- read.dta("https://teaching.sociology.ul.ie/so5041/ocorr.dta"), explore the correlations between the variables it contains, graphically and with the correlation coefficient.

Linear Regression

Load the National Longitudinal Study of Women data set and look at wage, the hourly wage rate. Predict wage using grade:

nlsw88 <- read.dta("https://teaching.sociology.ul.ie/so5041/nlsw88.dta")
summary(nlsw88$wage)
summary(nlsw88$grade)
cor(nlsw88$wage,nlsw88$grade)
plot(nlsw88$wage,nlsw88$grade)
summary(lm(nlsw88$wage ~ nlsw88$grade))

Write out the Y = a + bx equation. Calculate the predicted value for grade=0 and grade=20, and draw the line on a graph (on paper).

Practice app: https://teaching.sociology.ul.ie/apps/bivar/