DataM: HW Exercise 0316 2, 4, & 5
HW exercise 2.
- Rolling three dice for 100,000 times and record the results
- Find all possible sums.
[1] 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
- Construct a histogram for the sum of three dice.
This is an empirical histogram because it is based on the observed data, instead of the theory.
HW exercise 4.
The usBirths2015.txt is a dataset of monthly births in the US in 2015. Summarize the number of births by season.
[Solution and Answer]
- Load in the data set and check its structure
'data.frame': 12 obs. of 2 variables:
$ birth: int 325955 298058 328923 320832 327917 330541 353415 351791 347516 339007 ...
$ month: Factor w/ 12 levels "April","August",..: 5 4 8 1 9 7 6 2 12 11 ...
- Create a variable
season.
dta4 <- dta4[c(2:12, 1),]
dta4$season <- c('spring', 'summer', 'fall', 'winter')[rep(1:4, each=3)]
dta4- Summarize the number of births by season.
df <- aggregate(birth ~ season, mean, data = dta4)
df$SD <- aggregate(birth ~ season, sd, data = dta4)$birth
colnames(df)[2] <- 'MEAN'
df
HW exercise 5.
Ten subjects read a paragraph consisting of seven sentences. The reading time (in seconds) for each sentence was the outcome measure. The predictors are the serial position of the sentence (Sp), the number of words in the sentences (Wrds), and the number of new arguments in the sentence (New).
(a) Rank subjects by their reading speeed.
(b) Estimate, on average, how long does it take to read a word.
Source: Lorch, R.F., & Myers, J.L. (1990). Regression analyses of repeated measures data in cognitive research. Journal of Experimental Psychology: Learning, Memory, and Cognition. 16, 149-157.
[Solution and Answer]
'data.frame': 7 obs. of 14 variables:
$ Snt : int 1 2 3 4 5 6 7
$ Sp : int 1 2 3 4 5 6 7
$ Wrds: int 13 16 9 9 10 18 6
$ New : int 1 3 2 2 3 4 1
$ S01 : num 3.43 6.48 1.71 3.68 4 ...
$ S02 : num 2.79 5.41 2.34 3.71 2.9 ...
$ S03 : num 4.16 4.49 3.02 2.87 2.99 ...
$ S04 : num 3.07 5.06 2.46 2.73 2.67 ...
$ S05 : num 3.62 9.29 6.04 4.21 3.88 ...
$ S06 : num 3.16 5.64 2.46 6.24 3.22 ...
$ S07 : num 3.23 8.36 4.92 3.72 3.14 ...
$ S08 : num 7.16 4.31 3.37 6.33 6.14 ...
$ S09 : num 1.54 2.95 1.38 1.15 2.76 ...
$ S10 : num 4.06 6.65 2.18 3.66 3.33 ...
(a) Rank subjects by their reading speeed.
- Rank the subjects by their average reading time in the ascending order (i.e., the first one is the fastest reader).
S09 S03 S04 S02 S01 S10 S08 S07
2.741000 3.774286 3.779286 3.847000 4.130143 4.493714 5.011429 5.228429
S06 S05
5.371286 5.620000
barplot(sort(colMeans(dta5)[-(1:4)]), col = heat.colors(10),
xlab = 'Subject', ylab = 'Average Reading Time (s)')
(b) Estimate, on average, how long does it take to read a word.
[1] 0.3783395
On average, it takes about 0.3783 second to read a word.