Created
May 17, 2012 15:56
-
-
Save JoFrhwld/2719770 to your computer and use it in GitHub Desktop.
For a blog post on calculating probabilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## You need to model the "failures" | |
psm$Del <- 1-psm$td | |
mod <- glmer(Del ~ Gram2 + (Gram2|Speaker) + (1|Word), data = psm, family = binomial(link = cloglog)) | |
j3 <- exp(fixef(mod)["Gram2semiweak"]) | |
k3 <- exp(fixef(mod)["Gram2mono"]) | |
c(j1, k1) | |
## semiweak mono | |
## 1.913918 3.099787 | |
c(j2, k2) | |
## semiweak mono | |
## 1.335928 2.046796 | |
c(j3, k3) | |
## Gram2semiweak Gram2mono | |
## 1.375976 2.112944 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## What if we don't have any by-word random effects? | |
mod2 <- glmer(Del ~ Gram2 + (Gram2|Speaker), data = psm, family =binomial(link = cloglog)) | |
j4 <- exp(fixef(mod2)["Gram2semiweak"]) | |
k4 <- exp(fixef(mod2)["Gram2mono"]) | |
c(j1, k1) | |
## semiweak mono | |
## 1.913918 3.099787 | |
c(j2, k2) | |
## semiweak mono | |
## 1.335928 2.046796 | |
c(j3, k3) | |
## Gram2semiweak Gram2mono | |
## 1.375976 2.112944 | |
c(j4, k4) | |
## Gram2semiweak Gram2mono | |
## 1.565090 3.193196 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(plyr) | |
library(lme4) | |
library(RCurl) | |
b <- read.delim(textConnection(getURL("https://raw.github.com/JoFrhwld/TD-Classifier/master/Data/new_buckeye.txt"))) | |
eval(parse(text = getURL("https://raw.github.com/JoFrhwld/TD-Classifier/master/R/buckCoder.R"))) | |
b <- subset(b, !(FolSeg %in% c("apical")) & PreSeg != "/r/") | |
psm <- subset(b, Gram2 %in% c("past","semiweak","mono")) | |
psm$Word <- as.character(psm$Word) | |
psm$Gram2 <- as.factor(psm$Gram2) | |
psm$Gram2 <- relevel(psm$Gram2, "past") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Calculate proportion of pronounced /t d/ | |
### First within speaker within grammatical class within word | |
### Then within speaker within grammatical class | |
### Then within grammatical class | |
td.speaker.gram.word <- ddply(psm, .(Speaker, Gram2, Word), summarise, | |
td = mean(td), .progress = "text") | |
td.speaker.gram <- ddply(td.speaker.gram.word, .(Speaker, Gram2), summarise, | |
td = mean(td)) | |
td.gram <- ddply(td.speaker.gram, .(Gram2), summarise, | |
td = mean(td)) | |
td.gram.v <- td.gram$td | |
names(td.gram.v) <- td.gram$Gram2 | |
j2 = log(td.gram.v["semiweak"])/log(td.gram.v["past"]) | |
k2 = log(td.gram.v["mono"])/log(td.gram.v["past"]) | |
c(j1, k1) | |
## semiweak mono | |
## 1.913918 3.099787 | |
c(j2, k2) | |
## semiweak mono | |
## 1.335928 2.046796 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Calculate proportion of pronounced /t d/, collapsing across all speakers and words | |
td.mean1.df <- ddply(psm, .(Gram2), summarise, td = mean(td)) | |
td.mean1.v <- td.mean1.df$td | |
names(td.mean1.v) <- td.mean1.df$Gram2 | |
j1 = log(td.mean1.v["semiweak"])/log(td.mean1.v["past"]) | |
k1 = log(td.mean1.v["mono"])/log(td.mean1.v["past"]) | |
c(j1, k1) | |
## semiweak mono | |
## 1.913918 3.099787 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment