Vignettes are long form documentation commonly included in packages. Because they are part of the distribution of the package, they need to be as compact as possible. The html_pretty output format in package prettydoc , an alternative to html_document and html_vignette contained in the rmarkdown package, is able to generate small and nice HTML pages.
h2:Find all possible sums from rolling three dice using R. If possible, construct a histogram for the sum of three dice. Is this a probability histogram or an empirical histogram?
## [[1]]
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 2 3 4 5 6 7
## [2,] 3 4 5 6 7 8
## [3,] 4 5 6 7 8 9
## [4,] 5 6 7 8 9 10
## [5,] 6 7 8 9 10 11
## [6,] 7 8 9 10 11 12
## [7,] 8 9 10 11 12 13
## [8,] 9 10 11 12 13 14
## [9,] 10 11 12 13 14 15
## [10,] 11 12 13 14 15 16
## [11,] 12 13 14 15 16 17
## [12,] 13 14 15 16 17 18
h3:The IQ and behavior problem page has a dataset and a script of R code chunks. Generate a markdown file from the script to push the output in HTML for posting to course Moodle site. Explain what the code chunks do with your comments in the markdown file.
## 'data.frame': 94 obs. of 3 variables:
## $ Dep: Factor w/ 2 levels "D","N": 2 2 2 2 1 2 2 2 2 2 ...
## $ IQ : int 103 124 124 104 96 92 124 99 92 116 ...
## $ BP : int 4 12 9 3 3 3 6 4 3 9 ...
## [1] "data.frame"
## [1] 94 3
## [1] "Dep" "IQ" "BP"
## [1] TRUE
## Dep IQ BP
## 1 N 103 4
## [1] 103 124 124
## Dep IQ BP
## 16 N 89 11
## 58 N 117 11
## 66 N 126 11
## 2 N 124 12
## 73 D 99 13
## 12 D 22 17
## Dep IQ BP
## 77 N 124 1
## 80 N 121 1
## 24 N 106 0
## 75 N 122 0
plot(IQ ~ BP, data = dta, pch = 20, col = dta$Dep,
xlab = "Behavior problem score", ylab = "IQ")
grid()plot(BP ~ IQ, data = dta, type = "n",
ylab = "Behavior problem score", xlab = "IQ")
text(dta$IQ, dta$BP, labels = dta$Dep, cex = 0.5)
abline(lm(BP ~ IQ, data = dta, subset = Dep == "D"))
abline(lm(BP ~ IQ, data = dta, subset = Dep == "N"), lty = 2)h4:The usBirths2015.txt is a dataset of monthly births in the US in 2015. Summarize the number of births by season.
## '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 ...
Season <- c("Spring","Spring","Spring","Summer","Summer","Summer","Autumn","Autumn","Autumn","Winter","Winter","Winter")
dta$season <- Season
aggregate(birth ~ season, mean, data=dta)## season birth
## 1 Autumn 350907.3
## 2 Spring 317645.3
## 3 Summer 326430.0
## 4 Winter 331183.0
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).
## '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 ...
## [[1]]
## Snt Sp Wrds New S01 S02 S03 S04 S05 S06 S07 S08 S09 S10
## 1 1 1 13 1 3.429 2.795 4.161 3.071 3.625 3.161 3.232 7.161 1.536 4.063
## 2 2 2 16 3 6.482 5.411 4.491 5.063 9.295 5.643 8.357 4.313 2.946 6.652
## 3 3 3 9 2 1.714 2.339 3.018 2.464 6.045 2.455 4.920 3.366 1.375 2.179
## 4 4 4 9 2 3.679 3.714 2.866 2.732 4.205 6.241 3.723 6.330 1.152 3.661
## 5 5 5 10 3 4.000 2.902 2.991 2.670 3.884 3.223 3.143 6.143 2.759 3.330
## 6 6 6 18 4 6.973 8.018 6.625 7.571 8.795 13.188 11.170 6.071 7.964 7.866
## 7 7 7 6 1 2.634 1.750 2.268 2.884 3.491 3.688 2.054 1.696 1.455 3.705
## (a) Rank subjects by their reading speeed
dtac <- dta[,5:14]
dtacm <- apply(dtac, 2, mean)
order(dtacm)## [1] 9 3 4 2 1 10 8 7 6 5
## (b) Estimate, on average, how long does it take to read a word.
dtacs <- dtac/dta[,3]
dtacsw <- apply(dtacs, 2, mean)
dtacsw## S01 S02 S03 S04 S05 S06 S07 S08
## 0.3563579 0.3218649 0.3285283 0.3283256 0.4939310 0.4616710 0.4297786 0.4474266
## S09 S10
## 0.2205573 0.3949539