# Rnote4.1.R # (c) 2010 by Mary E. Beckman, Linguistics Department, Ohio # State University. Code for use with the Ling 286 textbook # Analyzing the Sounds of Languages. # Shows how to calculate the mean proportional deviation from # the expected counts of different outcomes in experiments with # a die roll simulator. # Assign the vectors of observed counts to appropriately named # variables, giving names to the counts, to remind yourself # which count is for which of the six outcomes of the die roll. x3 <- c(Ones=1, Twos=4, Threes=1, Fours=1, Fives=2, Sixes=3) x5 <- c(Ones=18, Twos=22, Threes=25, Fours=19, Fives=17, Sixes=19) x6 <- c(Ones=1996, Twos=2028, Threes=1955, Fours=2004, Fives=1982, Sixes=2035) # Subtract the expected count to get the vector of absolute # differences. x3-2 x5-20 x6-2000 # Divide that vector by the expected count to get the proportional # deviation. (x3-2)/2 (x5-20)/20 (x6-2000)/2000 # Use the abs() function to convert to the absolute value. abs((x3-2)/2) abs((x5-20)/20) abs((x6-2000)/2000) # Use the mean() function to see the average percentage deviation mean(abs((x3-2)/2)) mean(abs((x5-20)/20)) mean(abs((x6-2000)/2000)) # Multiply by 100 if you prefer percentages. mean(abs((x3-2)/2))*100 mean(abs((x5-20)/20))*100 mean(abs((x6-2000)/2000))*100