Generalized Linear Models

This week we will practice fitting generalized linear models. These sound complicated but are just extensions of the good old y=mx+b from 9th grade math. Epidemiologists use these models for estimating a variety of effect measures like risk differences, risk ratios, odds ratios, and the like. We won’t talk much about what goes in the model, but we’ll practice plugging our data and model specifications into R.

We’ll also finish up some basic data management from last time.

Lecture: Learn RData Management2014

Lab:GLMs

Data: greensboro.RData

Code:

# point this where your data is.
load("Desktop/greensboro.RData")
library(sp)

pdf("mymap.pdf")
plot(greensboro)
dev.off()

names(greensboro)

p.black <- greensboro$pop.black/greensboro$pop.total
l
ength(greensboro$pop.black)
length(greensboro$distance)/6130

d <- matrix(greensboro$distance,ncol=8)
dim(d)
d.min <- apply(d,1,min)
length(d.min) # looks good

#classify data
close <- 1*(d.min < 5280)
black 0.5)

summary(d.min)
table(close)

mod.linear <- glm(close~black)
summary(mod.linear)
confint(mod.linear)