楼主: 大家开心
56056 320

[学科前沿] Using R and RStudio for Data Management, Statistical Analysis and Graphics   [推广有奖]

231
stardust2010(未真实交易用户) 发表于 2016-2-2 12:09:13
支持!感谢楼主分享!

232
otising(真实交易用户) 发表于 2016-2-9 13:54:40
谢谢楼主

233
pkl(真实交易用户) 在职认证  发表于 2016-2-19 18:36:42
感谢楼主的分享,下载下来学习学习!

234
书海溪流(真实交易用户) 发表于 2016-3-25 07:54:09
多谢分享。

235
Akybat(真实交易用户) 发表于 2016-3-27 19:59:08
已购买,下载来看看

236
bfzldh(未真实交易用户) 学生认证  发表于 2016-3-28 08:49:16
看目录就知道这本书很经典,赞!感谢楼主。
  1. Contents
  2. List of Tables xvii
  3. List of Figures xix
  4. Preface to the second edition xxi
  5. Preface to the first edition xxiii
  6. 1 Data input and output 1
  7. 1.1 Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
  8. 1.1.1 Native dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
  9. 1.1.2 Fixed format text files . . . . . . . . . . . . . . . . . . . . . . . . . .1
  10. 1.1.3 Other fixed files . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
  11. 1.1.4 Comma-separated value (CSV) files . . . . . . . . . . . . . . . . . .      2
  12. 1.1.5 Read sheets from an Excel file . . . . . . . . . . . . . . . . . . . . .   2
  13. 1.1.6 Read data from R into SAS . . . . . . . . . . . . . . . . . . . . . . .    2
  14. 1.1.7 Read data from SAS into R . . . . . . . . . . . . . . . . . . . . . . .    3
  15. 1.1.8 Reading datasets in other formats . . . . . . . . . . . . . . . . . . .    3
  16. 1.1.9 Reading more complex text files . . . . . . . . . . . . . . . . . . . . 3
  17. 1.1.10 Reading data with a variable number of words in a field . . . . . . . 4
  18. 1.1.11 Read a file byte by byte . . . . . . . . . . . . . . . . . . . . . . . . . 5
  19. 1.1.12 Access data from a URL . . . . . . . . . . . . . . . . . . . . . . . . . 5
  20. 1.1.13 Read an XML-formatted file . . . . . . . . . . . . . . . . . . . . . . 6
  21. 1.1.14 Read an HTML table . . . . . . . . . . . . . . . . . . . . . . . . . . 6
  22. 1.1.15 Manual data entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
  23. 1.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
  24. 1.2.1 Displaying data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
  25. 1.2.2 Number of digits to display . . . . . . . . . . . . . . . . . . . . . . . 7
  26. 1.2.3 Save a native dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
  27. 1.2.4 Creating datasets in text format . . . . . . . . . . . . . . . . . . . . 8
  28. 1.2.5 Creating Excel spreadsheets . . . . . . . . . . . . . . . . . . . . . . . 8
  29. 1.2.6 Creating files for use by other packages . . . . . . . . . . . . . . . . 8
  30. 1.2.7 Creating HTML formatted output . . . . . . . . . . . . . . . . . . . 8
  31. 1.2.8 Creating XML datasets and output . . . . . . . . . . . . . . . . . . . 9
  32. 1.3 Further resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

  33. 2 Data management 11
  34. 2.1 Structure and metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
  35. 2.1.1 Access variables from a dataset . . . . . . . . . . . . . . . . . . . . . 11
  36. 2.1.2 Names of variables and their types . . . . . . . . . . . . . . . . . . . 11
  37. 2.1.3 Values of variables in a dataset . . . . . . . . . . . . . . . . . . . . . 12
  38. 2.1.4 Label variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
  39. 2.1.5 Add comment to a dataset or variable . . . . . . . . . . . . . . . . . 12
  40. 2.2 Derived variables and data manipulation . . . . . . . . . . . . . . . . . . . . 12
  41. 2.2.1 Add derived variable to a dataset . . . . . . . . . . . . . . . . . . . . 13
  42. 2.2.2 Rename variables in a dataset . . . . . . . . . . . . . . . . . . . . . . 13
  43. 2.2.3 Create string variables from numeric variables . . . . . . . . . . . . . 13
  44. 2.2.4 Create categorical variables from continuous variables . . . . . . . . 13
  45. 2.2.5 Recode a categorical variable . . . . . . . . . . . . . . . . . . . . . . 14
  46. 2.2.6 Create a categorical variable using logic . . . . . . . . . . . . . . . . 14
  47. 2.2.7 Create numeric variables from string variables . . . . . . . . . . . . . 15
  48. 2.2.8 Extract characters from string variables . . . . . . . . . . . . . . . . 15
  49. 2.2.9 Length of string variables . . . . . . . . . . . . . . . . . . . . . . . . 15
  50. 2.2.10 Concatenate string variables . . . . . . . . . . . . . . . . . . . . . . . 15
  51. 2.2.11 Set operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
  52. 2.2.12 Find strings within string variables . . . . . . . . . . . . . . . . . . . 16
  53. 2.2.13 Find approximate strings . . . . . . . . . . . . . . . . . . . . . . . . 16
  54. 2.2.14 Replace strings within string variables . . . . . . . . . . . . . . . . . 17
  55. 2.2.15 Split strings into multiple strings . . . . . . . . . . . . . . . . . . . . 17
  56. 2.2.16 Remove spaces around string variables . . . . . . . . . . . . . . . . . 17
  57. 2.2.17 Convert strings from upper to lower case . . . . . . . . . . . . . . . 17
  58. 2.2.18 Create lagged variable . . . . . . . . . . . . . . . . . . . . . . . . . . 17
  59. 2.2.19 Formatting values of variables . . . . . . . . . . . . . . . . . . . . . . 18
  60. 2.2.20 Perl interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
  61. 2.2.21 Accessing databases using SQL . . . . . . . . . . . . . . . . . . . . . 18
  62. 2.3 Merging, combining, and subsetting datasets . . . . . . . . . . . . . . . . . 19
  63. 2.3.1 Subsetting observations . . . . . . . . . . . . . . . . . . . . . . . . . 19
  64. 2.3.2 Drop or keep variables in a dataset . . . . . . . . . . . . . . . . . . . 19
  65. 2.3.3 Random sample of a dataset . . . . . . . . . . . . . . . . . . . . . . 20
  66. 2.3.4 Observation number . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
  67. 2.3.5 Keep unique values . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
  68. 2.3.6 Identify duplicated values . . . . . . . . . . . . . . . . . . . . . . . . 20
  69. 2.3.7 Convert from wide to long (tall) format . . . . . . . . . . . . . . . . 21
  70. 2.3.8 Convert from long (tall) to wide format . . . . . . . . . . . . . . . . 21
  71. 2.3.9 Concatenate and stack datasets . . . . . . . . . . . . . . . . . . . . . 22
  72. 2.3.10 Sort datasets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
  73. 2.3.11 Merge datasets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
  74. 2.4 Date and time variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
  75. 2.4.1 Create date variable . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
  76. 2.4.2 Extract weekday . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
  77. 2.4.3 Extract month . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
  78. 2.4.4 Extract year . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
  79. 2.4.5 Extract quarter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
  80. 2.4.6 Create time variable . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
  81. 2.5 Further resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
  82. 2.6 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
  83. 2.6.1 Data input and output . . . . . . . . . . . . . . . . . . . . . . . . . . 25

  84. 2.6.2 Data display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
  85. 2.6.3 Derived variables and data manipulation . . . . . . . . . . . . . . . . 27
  86. 2.6.4 Sorting and subsetting datasets . . . . . . . . . . . . . . . . . . . . . 31
  87. 3 Statistical and mathematical functions 33
  88. 3.1 Probability distributions and random number generation . . . . . . . . . . . 33
  89. 3.1.1 Probability density function . . . . . . . . . . . . . . . . . . . . . . . 33
  90. 3.1.2 Quantiles of a probability density function . . . . . . . . . . . . . . . 33
  91. 3.1.3 Setting the random number seed . . . . . . . . . . . . . . . . . . . . 34
  92. 3.1.4 Uniform random variables . . . . . . . . . . . . . . . . . . . . . . . . 34
  93. 3.1.5 Multinomial random variables . . . . . . . . . . . . . . . . . . . . . . 35
  94. 3.1.6 Normal random variables . . . . . . . . . . . . . . . . . . . . . . . . 35
  95. 3.1.7 Multivariate normal random variables . . . . . . . . . . . . . . . . . 35
  96. 3.1.8 Truncated multivariate normal random variables . . . . . . . . . . . 36
  97. 3.1.9 Exponential random variables . . . . . . . . . . . . . . . . . . . . . . 36
  98. 3.1.10 Other random variables . . . . . . . . . . . . . . . . . . . . . . . . . 36
  99. 3.2 Mathematical functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
  100. 3.2.1 Basic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
  101. 3.2.2 Trigonometric functions . . . . . . . . . . . . . . . . . . . . . . . . . 37
  102. 3.2.3 Special functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
  103. 3.2.4 Integer functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
  104. 3.2.5 Comparisons of floating-point variables . . . . . . . . . . . . . . . . 38
  105. 3.2.6 Complex numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
  106. 3.2.7 Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
  107. 3.2.8 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
  108. 3.2.9 Optimization problems . . . . . . . . . . . . . . . . . . . . . . . . . . 39
  109. 3.3 Matrix operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
  110. 3.3.1 Create matrix from vector . . . . . . . . . . . . . . . . . . . . . . . . 39
  111. 3.3.2 Combine vectors or matrices . . . . . . . . . . . . . . . . . . . . . . 39
  112. 3.3.3 Matrix addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
  113. 3.3.4 Transpose matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
  114. 3.3.5 Find the dimension of a matrix or dataset . . . . . . . . . . . . . . . 40
  115. 3.3.6 Matrix multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . 40
  116. 3.3.7 Finding the inverse of a matrix . . . . . . . . . . . . . . . . . . . . . 40
  117. 3.3.8 Component-wise multiplication . . . . . . . . . . . . . . . . . . . . . 40
  118. 3.3.9 Create a submatrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
  119. 3.3.10 Create a diagonal matrix . . . . . . . . . . . . . . . . . . . . . . . . 40
  120. 3.3.11 Create a vector of diagonal elements . . . . . . . . . . . . . . . . . . 41
  121. 3.3.12 Create a vector from a matrix . . . . . . . . . . . . . . . . . . . . . . 41
  122. 3.3.13 Calculate the determinant . . . . . . . . . . . . . . . . . . . . . . . . 41
  123. 3.3.14 Find eigenvalues and eigenvectors . . . . . . . . . . . . . . . . . . . . 41
  124. 3.3.15 Find the singular value decomposition . . . . . . . . . . . . . . . . . 41
  125. 3.4 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
  126. 3.4.1 Probability distributions . . . . . . . . . . . . . . . . . . . . . . . . . 42
  127. 4 Programming and operating system interface 45
  128. 4.1 Control flow, programming, and data generation . . . . . . . . . . . . . . . 45
  129. 4.1.1 Looping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
  130. 4.1.2 Conditional execution . . . . . . . . . . . . . . . . . . . . . . . . . . 45
  131. 4.1.3 Sequence of values or patterns . . . . . . . . . . . . . . . . . . . . . 46
  132. 4.1.4 Perform an action repeatedly over a set of variables . . . . . . . . . 46

  133. 4.1.5 Grid of values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
  134. 4.1.6 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
  135. 4.1.7 Error recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
  136. 4.2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
  137. 4.3 Interactions with the operating system . . . . . . . . . . . . . . . . . . . . . 49
  138. 4.3.1 Timing commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
  139. 4.3.2 Suspend execution for a time interval . . . . . . . . . . . . . . . . . 49
  140. 4.3.3 Execute a command in the operating system . . . . . . . . . . . . . 49
  141. 4.3.4 Command history . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
  142. 4.3.5 Find working directory . . . . . . . . . . . . . . . . . . . . . . . . . . 49
  143. 4.3.6 Change working directory . . . . . . . . . . . . . . . . . . . . . . . . 50
  144. 4.3.7 List and access files . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
  145. 4.3.8 Create temporary file . . . . . . . . . . . . . . . . . . . . . . . . . . 50
  146. 4.3.9 Redirect output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
  147. 5 Common statistical procedures 51
  148. 5.1 Summary statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
  149. 5.1.1 Means and other summary statistics . . . . . . . . . . . . . . . . . . 51
  150. 5.1.2 Weighted means and other statistics . . . . . . . . . . . . . . . . . . 51
  151. 5.1.3 Other moments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
  152. 5.1.4 Trimmed mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
  153. 5.1.5 Quantiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
  154. 5.1.6 Centering, normalizing, and scaling . . . . . . . . . . . . . . . . . . . 52
  155. 5.1.7 Mean and 95% confidence interval . . . . . . . . . . . . . . . . . . . 52
  156. 5.1.8 Proportion and 95% confidence interval . . . . . . . . . . . . . . . . 53
  157. 5.1.9 Maximum likelihood estimation of parameters . . . . . . . . . . . . . 53
  158. 5.2 Bivariate statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
  159. 5.2.1 Epidemiologic statistics . . . . . . . . . . . . . . . . . . . . . . . . . 53
  160. 5.2.2 Test characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
  161. 5.2.3 Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
  162. 5.2.4 Kappa (agreement) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
  163. 5.3 Contingency tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
  164. 5.3.1 Display cross-classification table . . . . . . . . . . . . . . . . . . . . 55
  165. 5.3.2 Displaying missing value categories in a table . . . . . . . . . . . . . 55
  166. 5.3.3 Pearson chi-square statistic . . . . . . . . . . . . . . . . . . . . . . . 55
  167. 5.3.4 Cochran–Mantel–Haenszel test . . . . . . . . . . . . . . . . . . . . . 55
  168. 5.3.5 Cram′er’s V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
  169. 5.3.6 Fisher’s exact test . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
  170. 5.3.7 McNemar’s test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
  171. 5.4 Tests for continuous variables . . . . . . . . . . . . . . . . . . . . . . . . . . 56
  172. 5.4.1 Tests for normality . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
  173. 5.4.2 Student’s t-test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
  174. 5.4.3 Test for equal variances . . . . . . . . . . . . . . . . . . . . . . . . . 57
  175. 5.4.4 Nonparametric tests . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
  176. 5.4.5 Permutation test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
  177. 5.4.6 Logrank test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
  178. 5.5 Analytic power and sample size calculations . . . . . . . . . . . . . . . . . . 58
  179. 5.6 Further resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
  180. 5.7 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
  181. 5.7.1 Summary statistics and exploratory data analysis . . . . . . . . . . . 59
  182. 5.7.2 Bivariate relationships . . . . . . . . . . . . . . . . . . . . . . . . . . 60

  183. 5.7.3 Contingency tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
  184. 5.7.4 Two sample tests of continuous variables . . . . . . . . . . . . . . . 64
  185. 5.7.5 Survival analysis: logrank test . . . . . . . . . . . . . . . . . . . . . 65
  186. 6 Linear regression and ANOVA 67
  187. 6.1 Model fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
  188. 6.1.1 Linear regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
  189. 6.1.2 Linear regression with categorical covariates . . . . . . . . . . . . . . 68
  190. 6.1.3 Changing the reference category . . . . . . . . . . . . . . . . . . . . 68
  191. 6.1.4 Parameterization of categorical covariates . . . . . . . . . . . . . . . 68
  192. 6.1.5 Linear regression with no intercept . . . . . . . . . . . . . . . . . . . 69
  193. 6.1.6 Linear regression with interactions . . . . . . . . . . . . . . . . . . . 69
  194. 6.1.7 Linear regression with big data . . . . . . . . . . . . . . . . . . . . . 69
  195. 6.1.8 One-way analysis of variance . . . . . . . . . . . . . . . . . . . . . . 70
  196. 6.1.9 Analysis of variance with two or more factors . . . . . . . . . . . . . 70
  197. 6.2 Tests, contrasts, and linear functions of parameters . . . . . . . . . . . . . . 70
  198. 6.2.1 Joint null hypotheses: several parameters equal 0 . . . . . . . . . . . 70
  199. 6.2.2 Joint null hypotheses: sum of parameters . . . . . . . . . . . . . . . 70
  200. 6.2.3 Tests of equality of parameters . . . . . . . . . . . . . . . . . . . . . 70
  201. 6.2.4 Multiple comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . 71
  202. 6.2.5 Linear combinations of parameters . . . . . . . . . . . . . . . . . . . 71
  203. 6.3 Model results and diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . . 71
  204. 6.3.1 Predicted values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
  205. 6.3.2 Residuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
  206. 6.3.3 Standardized and Studentized residuals . . . . . . . . . . . . . . . . 72
  207. 6.3.4 Leverage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
  208. 6.3.5 Cook’s distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
  209. 6.3.6 DFFITs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
  210. 6.3.7 Diagnostic plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
  211. 6.3.8 Heteroscedasticity tests . . . . . . . . . . . . . . . . . . . . . . . . . 73
  212. 6.4 Model parameters and results . . . . . . . . . . . . . . . . . . . . . . . . . . 73
  213. 6.4.1 Parameter estimates . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
  214. 6.4.2 Standardized regression coefficients . . . . . . . . . . . . . . . . . . . 73
  215. 6.4.3 Coefficient plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
  216. 6.4.4 Standard errors of parameter estimates . . . . . . . . . . . . . . . . 74
  217. 6.4.5 Confidence interval for parameter estimates . . . . . . . . . . . . . . 74
  218. 6.4.6 Confidence limits for the mean . . . . . . . . . . . . . . . . . . . . . 74
  219. 6.4.7 Prediction limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
  220. 6.4.8 R-squared . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
  221. 6.4.9 Design and information matrix . . . . . . . . . . . . . . . . . . . . . 75
  222. 6.4.10 Covariance matrix of parameter estimates . . . . . . . . . . . . . . . 75
  223. 6.4.11 Correlation matrix of parameter estimates . . . . . . . . . . . . . . . 76
  224. 6.5 Further resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
  225. 6.6 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
  226. 6.6.1 Scatterplot with smooth fit . . . . . . . . . . . . . . . . . . . . . . . 76
  227. 6.6.2 Linear regression with interaction . . . . . . . . . . . . . . . . . . . . 77
  228. 6.6.3 Regression coefficient plot . . . . . . . . . . . . . . . . . . . . . . . . 81
  229. 6.6.4 Regression diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . . 81
  230. 6.6.5 Fitting a regression model separately for each value of another variable 83
  231. 6.6.6 Two-way ANOVA . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
  232. 6.6.7 Multiple comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . 87

  233. 6.6.8 Contrasts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
  234. 7 Regression generalizations and modeling 91
  235. 7.1 Generalized linear models . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
  236. 7.1.1 Logistic regression model . . . . . . . . . . . . . . . . . . . . . . . . 91
  237. 7.1.2 Conditional logistic regression model . . . . . . . . . . . . . . . . . . 91
  238. 7.1.3 Exact logistic regression . . . . . . . . . . . . . . . . . . . . . . . . . 92
  239. 7.1.4 Ordered logistic model . . . . . . . . . . . . . . . . . . . . . . . . . . 92
  240. 7.1.5 Generalized logistic model . . . . . . . . . . . . . . . . . . . . . . . . 93
  241. 7.1.6 Poisson model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
  242. 7.1.7 Negative binomial model . . . . . . . . . . . . . . . . . . . . . . . . 93
  243. 7.1.8 Log-linear model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
  244. 7.2 Further generalizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
  245. 7.2.1 Zero-inflated Poisson model . . . . . . . . . . . . . . . . . . . . . . . 93
  246. 7.2.2 Zero-inflated negative binomial model . . . . . . . . . . . . . . . . . 94
  247. 7.2.3 Generalized additive model . . . . . . . . . . . . . . . . . . . . . . . 94
  248. 7.2.4 Nonlinear least squares model . . . . . . . . . . . . . . . . . . . . . . 94
  249. 7.3 Robust methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
  250. 7.3.1 Quantile regression model . . . . . . . . . . . . . . . . . . . . . . . . 95
  251. 7.3.2 Robust regression model . . . . . . . . . . . . . . . . . . . . . . . . . 95
  252. 7.3.3 Ridge regression model . . . . . . . . . . . . . . . . . . . . . . . . . 95
  253. 7.4 Models for correlated data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
  254. 7.4.1 Linear models with correlated outcomes . . . . . . . . . . . . . . . . 96
  255. 7.4.2 Linear mixed models with random intercepts . . . . . . . . . . . . . 96
  256. 7.4.3 Linear mixed models with random slopes . . . . . . . . . . . . . . . 96
  257. 7.4.4 More complex random coefficient models . . . . . . . . . . . . . . . . 97
  258. 7.4.5 Multilevel models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
  259. 7.4.6 Generalized linear mixed models . . . . . . . . . . . . . . . . . . . . 97
  260. 7.4.7 Generalized estimating equations . . . . . . . . . . . . . . . . . . . . 97
  261. 7.4.8 MANOVA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
  262. 7.4.9 Time series model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
  263. 7.5 Survival analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
  264. 7.5.1 Proportional hazards (Cox) regression model . . . . . . . . . . . . . 98
  265. 7.5.2 Proportional hazards (Cox) model with frailty . . . . . . . . . . . . 99
  266. 7.5.3 Nelson–Aalen estimate of cumulative hazard . . . . . . . . . . . . . 99
  267. 7.5.4 Testing the proportionality of the Cox model . . . . . . . . . . . . . 99
  268. 7.5.5 Cox model with time-varying predictors . . . . . . . . . . . . . . . . 100
  269. 7.6 Multivariate statistics and discriminant procedures . . . . . . . . . . . . . . 100
  270. 7.6.1 Cronbach’s α . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
  271. 7.6.2 Factor analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
  272. 7.6.3 Recursive partitioning . . . . . . . . . . . . . . . . . . . . . . . . . . 100
  273. 7.6.4 Linear discriminant analysis . . . . . . . . . . . . . . . . . . . . . . . 100
  274. 7.6.5 Latent class analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
  275. 7.6.6 Hierarchical clustering . . . . . . . . . . . . . . . . . . . . . . . . . . 101
  276. 7.7 Complex survey design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
  277. 7.8 Model selection and assessment . . . . . . . . . . . . . . . . . . . . . . . . . 102
  278. 7.8.1 Compare two models . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
  279. 7.8.2 Log-likelihood . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
  280. 7.8.3 Akaike Information Criterion (AIC) . . . . . . . . . . . . . . . . . . 102
  281. 7.8.4 Bayesian Information Criterion (BIC) . . . . . . . . . . . . . . . . . 102
  282. 7.8.5 LASSO model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

  283. 7.8.6 Hosmer–Lemeshow goodness of fit . . . . . . . . . . . . . . . . . . . 103
  284. 7.8.7 Goodness of fit for count models . . . . . . . . . . . . . . . . . . . . 103
  285. 7.9 Further resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
  286. 7.10 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
  287. 7.10.1 Logistic regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
  288. 7.10.2 Poisson regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
  289. 7.10.3 Zero-inflated Poisson regression . . . . . . . . . . . . . . . . . . . . . 106
  290. 7.10.4 Negative binomial regression . . . . . . . . . . . . . . . . . . . . . . 107
  291. 7.10.5 Quantile regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
  292. 7.10.6 Ordered logistic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
  293. 7.10.7 Generalized logistic model . . . . . . . . . . . . . . . . . . . . . . . . 108
  294. 7.10.8 Generalized additive model . . . . . . . . . . . . . . . . . . . . . . . 109
  295. 7.10.9 Reshaping a dataset for longitudinal regression . . . . . . . . . . . . 110
  296. 7.10.10 Linear model for correlated data . . . . . . . . . . . . . . . . . . . . 112
  297. 7.10.11 Linear mixed (random slope) model . . . . . . . . . . . . . . . . . . 113
  298. 7.10.12 Generalized estimating equations . . . . . . . . . . . . . . . . . . . . 115
  299. 7.10.13 Generalized linear mixed model . . . . . . . . . . . . . . . . . . . . . 116
  300. 7.10.14 Cox proportional hazards model . . . . . . . . . . . . . . . . . . . . 117
  301. 7.10.15 Cronbach’s α . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
  302. 7.10.16 Factor analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
  303. 7.10.17 Recursive partitioning . . . . . . . . . . . . . . . . . . . . . . . . . . 119
  304. 7.10.18 Linear discriminant analysis . . . . . . . . . . . . . . . . . . . . . . . 120
  305. 7.10.19 Hierarchical clustering . . . . . . . . . . . . . . . . . . . . . . . . . . 121
  306. 8 A graphical compendium 123
  307. 8.1 Univariate plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
  308. 8.1.1 Barplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
  309. 8.1.2 Stem-and-leaf plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
  310. 8.1.3 Dotplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
  311. 8.1.4 Histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
  312. 8.1.5 Density plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
  313. 8.1.6 Empirical cumulative probability density plot . . . . . . . . . . . . . 125
  314. 8.1.7 Boxplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
  315. 8.1.8 Violin plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
  316. 8.2 Univariate plots by grouping variable . . . . . . . . . . . . . . . . . . . . . . 125
  317. 8.2.1 Side-by-side histograms . . . . . . . . . . . . . . . . . . . . . . . . . 125
  318. 8.2.2 Side-by-side boxplots . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
  319. 8.2.3 Overlaid density plots . . . . . . . . . . . . . . . . . . . . . . . . . . 126
  320. 8.2.4 Bar chart with error bars . . . . . . . . . . . . . . . . . . . . . . . . 126
  321. 8.3 Bivariate plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
  322. 8.3.1 Scatterplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
  323. 8.3.2 Scatterplot with multiple y values . . . . . . . . . . . . . . . . . . . 127
  324. 8.3.3 Scatterplot with binning . . . . . . . . . . . . . . . . . . . . . . . . . 128
  325. 8.3.4 Transparent overplotting scatterplot . . . . . . . . . . . . . . . . . . 128
  326. 8.3.5 Bivariate density plot . . . . . . . . . . . . . . . . . . . . . . . . . . 128
  327. 8.3.6 Scatterplot with marginal histograms . . . . . . . . . . . . . . . . . 129
  328. 8.4 Multivariate plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
  329. 8.4.1 Matrix of scatterplots . . . . . . . . . . . . . . . . . . . . . . . . . . 129
  330. 8.4.2 Conditioning plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
  331. 8.4.3 Contour plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
  332. 8.4.4 3-D plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

  333. 8.5 Special-purpose plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
  334. 8.5.1 Choropleth maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
  335. 8.5.2 Interaction plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
  336. 8.5.3 Plots for categorical data . . . . . . . . . . . . . . . . . . . . . . . . 131
  337. 8.5.4 Circular plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
  338. 8.5.5 Plot an arbitrary function . . . . . . . . . . . . . . . . . . . . . . . . 131
  339. 8.5.6 Normal quantile–quantile plot . . . . . . . . . . . . . . . . . . . . . . 131
  340. 8.5.7 Receiver operating characteristic (ROC) curve . . . . . . . . . . . . 132
  341. 8.5.8 Plot confidence intervals for the mean . . . . . . . . . . . . . . . . . 132
  342. 8.5.9 Plot prediction limits from a simple linear regression . . . . . . . . . 132
  343. 8.5.10 Plot predicted lines for each value of a variable . . . . . . . . . . . . 132
  344. 8.5.11 Kaplan–Meier plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
  345. 8.5.12 Hazard function plotting . . . . . . . . . . . . . . . . . . . . . . . . . 133
  346. 8.5.13 Mean–difference plots . . . . . . . . . . . . . . . . . . . . . . . . . . 133
  347. 8.6 Further resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
  348. 8.7 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
  349. 8.7.1 Scatterplot with multiple axes . . . . . . . . . . . . . . . . . . . . . 134
  350. 8.7.2 Conditioning plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
  351. 8.7.3 Scatterplot with marginal histograms . . . . . . . . . . . . . . . . . 135
  352. 8.7.4 Kaplan–Meier plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
  353. 8.7.5 ROC curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
  354. 8.7.6 Pairs plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
  355. 8.7.7 Visualize correlation matrix . . . . . . . . . . . . . . . . . . . . . . . 141
  356. 9 Graphical options and configuration 145
  357. 9.1 Adding elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
  358. 9.1.1 Arbitrary straight line . . . . . . . . . . . . . . . . . . . . . . . . . . 145
  359. 9.1.2 Plot symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
  360. 9.1.3 Add points to an existing graphic . . . . . . . . . . . . . . . . . . . . 146
  361. 9.1.4 Jitter points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
  362. 9.1.5 Regression line fit to points . . . . . . . . . . . . . . . . . . . . . . . 146
  363. 9.1.6 Smoothed line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
  364. 9.1.7 Normal density . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
  365. 9.1.8 Marginal rug plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
  366. 9.1.9 Titles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
  367. 9.1.10 Footnotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
  368. 9.1.11 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
  369. 9.1.12 Mathematical symbols . . . . . . . . . . . . . . . . . . . . . . . . . . 148
  370. 9.1.13 Arrows and shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
  371. 9.1.14 Add grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
  372. 9.1.15 Legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
  373. 9.1.16 Identifying and locating points . . . . . . . . . . . . . . . . . . . . . 148
  374. 9.2 Options and parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
  375. 9.2.1 Graph size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
  376. 9.2.2 Grid of plots per page . . . . . . . . . . . . . . . . . . . . . . . . . . 149
  377. 9.2.3 More general page layouts . . . . . . . . . . . . . . . . . . . . . . . . 149
  378. 9.2.4 Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
  379. 9.2.5 Point and text size . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
  380. 9.2.6 Box around plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
  381. 9.2.7 Size of margins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
  382. 9.2.8 Graphical settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

  383. 9.2.9 Axis range and style . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
  384. 9.2.10 Axis labels, values, and tick marks . . . . . . . . . . . . . . . . . . . 151
  385. 9.2.11 Line styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
  386. 9.2.12 Line widths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
  387. 9.2.13 Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
  388. 9.2.14 Log scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
  389. 9.2.15 Omit axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
  390. 9.3 Saving graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
  391. 9.3.1 PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
  392. 9.3.2 Postscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
  393. 9.3.3 RTF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
  394. 9.3.4 JPEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
  395. 9.3.5 Windows Metafile . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
  396. 9.3.6 Bitmap image file (BMP) . . . . . . . . . . . . . . . . . . . . . . . . 153
  397. 9.3.7 Tagged Image File Format . . . . . . . . . . . . . . . . . . . . . . . . 153
  398. 9.3.8 PNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
  399. 9.3.9 Closing a graphic device . . . . . . . . . . . . . . . . . . . . . . . . . 153
  400. 10 Simulation 155
  401. 10.1 Generating data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
  402. 10.1.1 Generate categorical data . . . . . . . . . . . . . . . . . . . . . . . . 155
  403. 10.1.2 Generate data from a logistic regression . . . . . . . . . . . . . . . . 156
  404. 10.1.3 Generate data from a generalized linear mixed model . . . . . . . . . 156
  405. 10.1.4 Generate correlated binary data . . . . . . . . . . . . . . . . . . . . 157
  406. 10.1.5 Generate data from a Cox model . . . . . . . . . . . . . . . . . . . . 158
  407. 10.1.6 Sampling from a challenging distribution . . . . . . . . . . . . . . . 159
  408. 10.2 Simulation applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
  409. 10.2.1 Simulation study of Student’s t-test . . . . . . . . . . . . . . . . . . 161
  410. 10.2.2 Diploma (or hat-check) problem . . . . . . . . . . . . . . . . . . . . 162
  411. 10.2.3 Monty Hall problem . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
  412. 10.2.4 Censored survival . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
  413. 10.3 Further resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
  414. 11 Special topics 167
  415. 11.1 Processing by group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
  416. 11.1.1 Means by group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
  417. 11.1.2 Linear models stratified by each value of a grouping variable . . . . 168
  418. 11.2 Simulation-based power calculations . . . . . . . . . . . . . . . . . . . . . . 169
  419. 11.3 Reproducible analysis and output . . . . . . . . . . . . . . . . . . . . . . . . 171
  420. 11.4 Advanced statistical methods . . . . . . . . . . . . . . . . . . . . . . . . . . 173
  421. 11.4.1 Bayesian methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
  422. 11.4.2 Propensity scores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
  423. 11.4.3 Bootstrapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
  424. 11.4.4 Missing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
  425. 11.4.5 Finite mixture models with concomitant variables . . . . . . . . . . 185
  426. 11.5 Further resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

  427. 12 Case studies 187
  428. 12.1 Data management and related tasks . . . . . . . . . . . . . . . . . . . . . . 187
  429. 12.1.1 Finding two closest values in a vector . . . . . . . . . . . . . . . . . 187
  430. 12.1.2 Tabulate binomial probabilities . . . . . . . . . . . . . . . . . . . . . 188
  431. 12.1.3 Calculate and plot a running average . . . . . . . . . . . . . . . . . . 188
  432. 12.1.4 Create a Fibonacci sequence . . . . . . . . . . . . . . . . . . . . . . . 189
  433. 12.2 Read variable format files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
  434. 12.3 Plotting maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
  435. 12.3.1 Massachusetts counties, continued . . . . . . . . . . . . . . . . . . . 192
  436. 12.3.2 Bike ride plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
  437. 12.3.3 Choropleth maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
  438. 12.4 Data scraping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
  439. 12.4.1 Scraping data from HTML files . . . . . . . . . . . . . . . . . . . . . 195
  440. 12.4.2 Reading data with two lines per observation . . . . . . . . . . . . . . 196
  441. 12.4.3 Plotting time series data . . . . . . . . . . . . . . . . . . . . . . . . . 197
  442. 12.4.4 Reading tables from HTML . . . . . . . . . . . . . . . . . . . . . . . 198
  443. 12.4.5 URL APIs and truly random numbers . . . . . . . . . . . . . . . . . 199
  444. 12.4.6 Reading from a web API . . . . . . . . . . . . . . . . . . . . . . . . 200
  445. 12.5 Text mining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
  446. 12.5.1 Retrieving data from arXiv.org . . . . . . . . . . . . . . . . . . . . . 202
  447. 12.5.2 Exploratory text mining . . . . . . . . . . . . . . . . . . . . . . . . . 202
  448. 12.6 Interactive visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
  449. 12.6.1 Visualization using the grammar of graphics (ggvis) . . . . . . . . . 203
  450. 12.6.2 Shiny in Markdown . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
  451. 12.6.3 Creating a standalone Shiny app . . . . . . . . . . . . . . . . . . . . 206
  452. 12.7 Manipulating bigger datasets . . . . . . . . . . . . . . . . . . . . . . . . . . 207
  453. 12.8 Constrained optimization: the knapsack problem . . . . . . . . . . . . . . . 208
  454. A Introduction to R and RStudio 211
  455. A.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
  456. A.1.1 Installation under Windows . . . . . . . . . . . . . . . . . . . . . . . 212
  457. A.1.2 Installation under Mac OS X . . . . . . . . . . . . . . . . . . . . . . 213
  458. A.1.3 RStudio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
  459. A.1.4 Other graphical interfaces . . . . . . . . . . . . . . . . . . . . . . . . 213
  460. A.2 Running R and sample session . . . . . . . . . . . . . . . . . . . . . . . . . 214
  461. A.2.1 Replicating examples from the book and sourcing commands . . . . 215
  462. A.2.2 Batch mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
  463. A.3 Learning R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
  464. A.3.1 Getting help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
  465. A.3.2 swirl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
  466. A.4 Fundamental structures and objects . . . . . . . . . . . . . . . . . . . . . . 220
  467. A.4.1 Objects and vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
  468. A.4.2 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
  469. A.4.3 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
  470. A.4.4 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
  471. A.4.5 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
  472. A.4.6 Dataframes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
  473. A.4.7 Attributes and classes . . . . . . . . . . . . . . . . . . . . . . . . . . 226
  474. A.4.8 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
  475. A.5 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
  476. A.5.1 Calling functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226

  477. A.5.2 The apply family of functions . . . . . . . . . . . . . . . . . . . . . . 227
  478. A.5.3 Pipes and connections between functions . . . . . . . . . . . . . . . 228
  479. A.6 Add-ons: packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
  480. A.6.1 Introduction to packages . . . . . . . . . . . . . . . . . . . . . . . . . 229
  481. A.6.2 Packages and name conflicts . . . . . . . . . . . . . . . . . . . . . . . 230
  482. A.6.3 Maintaining packages . . . . . . . . . . . . . . . . . . . . . . . . . . 231
  483. A.6.4 CRAN task views . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
  484. A.6.5 Installed libraries and packages . . . . . . . . . . . . . . . . . . . . . 231
  485. A.6.6 Packages referenced in this book . . . . . . . . . . . . . . . . . . . . 233
  486. A.6.7 Datasets available with R . . . . . . . . . . . . . . . . . . . . . . . . 236
  487. A.7 Support and bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
  488. B The HELP study dataset 237
  489. B.1 Background on the HELP study . . . . . . . . . . . . . . . . . . . . . . . . 237
  490. B.2 Roadmap to analyses of the HELP dataset . . . . . . . . . . . . . . . . . . 237
  491. B.3 Detailed description of the dataset . . . . . . . . . . . . . . . . . . . . . . . 239
  492. C References 24
复制代码


书籍是人类进步的阶梯

237
幸福的守护(未真实交易用户) 发表于 2016-4-7 02:32:18
thanks a lot

238
sometiger(未真实交易用户) 发表于 2016-4-24 22:44:34
看着不错,过来支持一下!

239
调皮捣蛋大黑熊(真实交易用户) 发表于 2016-4-25 15:22:53
非常感谢楼主!已下载,一会儿好好看看哈哈

240
太极无极(真实交易用户) 在职认证  发表于 2016-4-25 23:59:18
这是一本好书

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-26 01:39