# R code for Labov (1965, 2006) department store study, from Gorman and 
# Johnson in press

source('ky.R')
options(contrasts = c('contr.sum', 'contr.poly'))

nyc <- read.csv('nyc.csv')

# univariate statistics 
mat <- matrix(xtabs(~ r + word, data=nyc), ncol=2)
chisq.test(mat)$p.value
fisher.test(mat)$p.value

mat <- matrix(xtabs(~ r + emphasis, data=nyc), ncol=2)
chisq.test(mat)$p.value
fisher.test(mat)$p.value

mat <- matrix(xtabs(~ r + store, data=nyc), ncol=3)
chisq.test(mat)$p.value
fisher.test(mat)$p.value

# logistic regression model
m0 <- glm(r ~ store * word + emphasis, data=nyc, family=binomial)
summary(m0, digits=4)
sum.coef(m0)
drop1(m0, test='Chisq')
