PC Labs for SO5032

Table of Contents

Week 1 Lab

Starsign

Does your star sign have an effect on whether you believe astrology is scientific??

Measures of association

We have discussed the following measures of association, defined for 2*2 tables:

  • Difference in proportions
  • Relative rate or ratio of proportions
  • Odds ratio

Calculate each of these measures for the following table:

  Outcome    
  No Yes Total
Type 1 380 120 500
Type 2 420 80 500
Total 800 200 1000

With a spreadsheet…

This spreadsheet will allow you to explore these measures a bit more. You can change the numbers in the "Type 1/Outcome Yes" and "Total/Outcome Yes" cells and the three measures are calculated for you. Use it to check what you have calculated by hand.

For "Total/Outcome Yes" values of 100, 200, 400, 800 and 900, do the following:

  • Find what values of "Type 1/Yes" give you a difference in

proportions of 0.2 for each of these totals

  • Find what values of "Type 1/Yes" give you a relative rate of 2.0

(or as close as possible) for each total

  • Find what values of "Type 1/Yes" give you odds ratio of 2.0

(or as close as possible) for each total

Keep a note of your numbers and compare their patterns. What do you notice?

Tables in R

R has lots of ways of making tables, but the results in base R are pretty poor. I've written a function to make slightly better tables. Download the tabxw.R file and save it in your working folder (I recommend you use something like C:\Users\yourname\so5032\labs\ or similar).

(Note that running R code downloaded from the web can be dangerous: make sure you know its origin.)

getwd() ## show where you are
setwd("C:/Users/yourname/so5032/labs/") ## note "/" not "\"
source("tabxw.R")

Once it is installed, load the NLSW88 data and try the following:

library(foreign)
nlsw88 <- read.dta("https://teaching.sociology.ul.ie/so5041/nlsw88.dta")
tabxw(nlsw88, occupation, union)

For percentages:

tabxw(nlsw88, occupation, union, tabtype="row")
tabxw(nlsw88, occupation, union, tabtype="col")

Expected values and residuals:

tabxw(nlsw88, occupation, union, tabtype="expected")
tabxw(nlsw88, occupation, union, tabtype="resid")