############### ## R WARM-UP ## ############### ### READ IN DATA FROM A COMMA-SEPARATED VALUES FILE ### DOWNLOAD FROM http://people.ucsc.edu/~mwagers/ling280/data/plurals.csv.gz > .... -> plurals summary(plurals) ### EXTRACT THE RTs > .... -> rt.plurals summary(rt.plurals) ### CONSTRUCT A HISTOGRAM WITH 25 ms BINS > .... ### INSTALL SOME NEW TOOLS install.packages("psych") require(psych) ### CREATE A NEW TOOL multiplot<-function(row,col) { par(mfrow = c(row,col),pty="s") par(mar=c(3,3,3,2)) } ### SIMULATE SOME COIN FLIPS rbinom(1500,4000,0.75)->coin.flips ### multiplot(2,2) hist(rt.plurals,breaks=seq(0,4000,50),main="RTs",freq=FALSE,xlim=c(0,2000)) hist(coin.flips,breaks=40,main="Coin flips",freq=FALSE) hist(-rt.plurals,breaks=seq(-4000,0,50),freq=FALSE,xlim=c(-2000,0)) #### WHAT IS BEING QUANTIFIED HERE? skew(rt.plurals) skew(coin.flips) skew(-rt.plurals) ###################### ## BINOMIAL WRAP-UP ## ###################### ### SUPPOSE THE LIKELIHOOD OF HEADS IS GIVEN BY p = 0.75 ### What is the choice of the head count being 20 for a 40-coin flip? > .... ### p = 0.75, 40 events, likelihood of count being 30 > .... ### p = 0.75, 4 events, likelihood of count being 3 > .... ### p = 0.75, 400 events, likelihood of count being 300 > .... ### INTERVALS/RANGES n.events <- 40 p.event <- 0.7 sim.events<- rbinom(10000, 40, 0.7) probs <- dbinom(0:n.events, n.events, p.event) plot(0:40, probs, col="red", lwd=3, pty='l') hist(sim.events, breaks=0:40, freq=FALSE, col="grey", density=20, add=1) abline( v = mean(sim.events) ) ### ### +/- 1 sum(probs[28:30]) abline( v = c(27, 29), col="blue",lwd=2) # remembers probs[1] corresponds to 0 heads ### +/- 2 sum(probs[27:31]) abline( v = c(26, 30), col="green", lwd=2) ### +/- 6 sum(probs[23:35]) abline( v = c(25, 31), col="purple", lwd=2)