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
theKingOfFrance = None | |
bald = ["JeanLucPicard", "StoneColdSteveAustin"] | |
print("Jean: The King of France is bald.") | |
if theKingOfFrance in bald: | |
print("Jaques: It's true!") | |
elif theKingOfFrance not in bald: | |
print("Jaques: It's false!") | |
print("") |
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
data.frame(SES = c("High","Middle","Low"), | |
Applied = c(0.79, 0.59, 0.5), | |
Admitted = c(0.67, 0.47, 0.42), | |
Enrolled = c(0.53, 0.28, 0.32)) -> data | |
ggplot(data, aes(SES)) + | |
geom_point(aes(y = Applied, color = "Applied"))+ | |
geom_line(aes(y = Applied, group = 1, color = "Applied"))+ | |
geom_point(aes(y = Admitted/Applied, color = "Applied and Admitted"))+ | |
geom_line(aes(group = 1, y = Admitted/Applied, color = "Applied and Admitted"))+ |
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
multi_match <- function(x, table){ | |
# returns initial indicies of all substrings in table which match x | |
if(length(table) < length(x)){ | |
return(NA) | |
}else{ | |
check_mat <- matrix(nrow = length(x), ncol = length(table)) | |
for(i in 1:length(x)){ | |
check_mat[i,] <- table %in% x[i] | |
} | |
out <- vector(length = length(table)) |
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
syllabify <- function(trans){ | |
require(stringr) | |
segments <- unlist(str_split(trans, " ")) | |
nuclei_string <- "A|E|I|O|U|@" | |
nucs <- grep(nuclei_string, segments) | |
n <- length(nucs) | |
r_colored <- nucs[grep("R", segments[nucs])] |
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(ggplot2) | |
library(grid) | |
bg <- data.frame(xmin = 0, xmax = 180, ymin = 0, ymax = 180) | |
bg_col <- rgb(0.8,0,0) | |
bars <- data.frame(xmin = c(35, 35), xmax = c(145, 145), ymin = c(45, 100), ymax = c(80, 135), groups = c("first", "second") ) | |
bars_col <- rgb(0.9, 0.56, 0.56) | |
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
# http://www.cdc.gov/nchs/data/nhsr/nhsr010.pdf | |
n_fem = 604 | |
h_fem = 162.2 | |
se_fem = 0.34 | |
sd_fem = se_fem * sqrt(n_fem) | |
n_mal = 591 | |
h_mal = 176.6 | |
se_mal = 0.38 |
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
#### Values created by statistics | |
Statistical layers added to plots actually create new pieces of data, like the y-coordinates of the smoother. Some statistical layers create a few different values, and you can choose which one you want to plot. For example, here is a density plot, where the kernel density estimate is represented by a colored line. | |
```{r tidy = F, fig.width = 8/1.2, fig.height=5/1.2} | |
ggplot(I_jean, aes(Dur_msec, color = Word))+ | |
geom_density() | |
``` | |
You have to understand the densities represented in this plot as being conditional on selecting a specific word. That is, given that we have decided to think about the lexical item "I've", what is the probability it will be found in a specific range of durations? |
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
ggplot(Vy, aes(F2, F1, shape = Vowel))+ | |
geom_point()+ | |
theme_bw()+ | |
scale_x_continuous(name = "F2", trans = revlog_trans())+ | |
scale_y_reverse(name = "F1")+ | |
stat_ellipse(level = 0.95)+ | |
opts(legend.position = "none")+ | |
annotate(geom="text", x=2900, y = 460, label = "iyC", size = 5)+ | |
annotate(geom="text", x=2400, y = 750, label = "eyC", size = 5)+ | |
annotate(geom="text", x=1850, y = 970, label = "ay", size = 5) |
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 |
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(ggplot2) | |
library(plyr) | |
## Set your effect size, and desired p-value threshold here | |
effect = 0.1 | |
thresh = 0.05 | |
## Sets up the simulation parameters | |
pars = list(mean1 = 1, mean2 = 1+effect, sd1 = 1, sd2 = 1) | |
nsim = 1000 |