前言

这是《统计分析(以R语言为工具)》一书所用R语言代码辅助材料,还在更新中。错漏之处难免,欢迎指出错误或提出改进意见。

相关下载

本书所使用的课件:

使用本教程必须安装的软件包

  • resahpe
  • reshape2
  • plyr
  • dplyr
  • readxl
  • lubridate
  • stringr
  • e1071
  • fBasics
  • tidyr
  • corrplot
  • ggplot2
  • zoo
  • plotly
  • purrr
  • data.table
  • magrittr
  • BSDA
  • pROC
  • ROCR
  • psych

本教程中用到的软件包列表(更新R软件后可以在一个基本R中运行如下命令):

pkgs <- c("resahpe", "reshape2", "plyr", "dplyr", "readxl", "lubridate", 
          "stringr", "e1071", "fBasics", "tidyr", "corrplot", "ggplot2",
          "zoo", "plotly", "purrr", "data.table", "magrittr", "BSDA",
          "pROC", "ROCR", "psych")
install.packages(unique(pkgs))

编译本教程所用的R软件环境:

devtools::session_info()
## ─ Session info ────────────────────────────────────────────────────────────────────
##  setting  value                       
##  version  R version 4.0.0 (2020-04-24)
##  os       macOS Catalina 10.15.7      
##  system   x86_64, darwin17.0          
##  ui       RStudio                     
##  language (EN)                        
##  collate  en_US.UTF-8                 
##  ctype    en_US.UTF-8                 
##  tz       Asia/Shanghai               
##  date     2020-12-02                  
## 
## ─ Packages ────────────────────────────────────────────────────────────────────────
##  package     * version   date       lib source        
##  assertthat    0.2.1     2019-03-21 [1] CRAN (R 4.0.0)
##  backports     1.1.10    2020-09-15 [1] CRAN (R 4.0.2)
##  bookdown      0.21      2020-10-13 [1] CRAN (R 4.0.0)
##  BSDA        * 1.2.0     2017-07-30 [1] CRAN (R 4.0.0)
##  callr         3.5.1     2020-10-13 [1] CRAN (R 4.0.2)
##  cellranger    1.1.0     2016-07-27 [1] CRAN (R 4.0.0)
##  class         7.3-16    2020-03-25 [1] CRAN (R 4.0.0)
##  cli           2.1.0     2020-10-12 [1] CRAN (R 4.0.2)
##  colorspace    1.4-1     2019-03-18 [1] CRAN (R 4.0.0)
##  corrplot    * 0.84      2017-10-16 [1] CRAN (R 4.0.0)
##  crayon        1.3.4     2017-09-16 [1] CRAN (R 4.0.0)
##  data.table  * 1.13.2    2020-10-19 [1] CRAN (R 4.0.2)
##  desc          1.2.0     2018-05-01 [1] CRAN (R 4.0.0)
##  devtools      2.3.0     2020-04-10 [1] CRAN (R 4.0.0)
##  digest        0.6.27    2020-10-24 [1] CRAN (R 4.0.2)
##  dplyr       * 1.0.2     2020-08-18 [1] CRAN (R 4.0.2)
##  e1071       * 1.7-3     2019-11-26 [1] CRAN (R 4.0.0)
##  ellipsis      0.3.1     2020-05-15 [1] CRAN (R 4.0.0)
##  evaluate      0.14      2019-05-28 [1] CRAN (R 4.0.0)
##  fansi         0.4.1     2020-01-08 [1] CRAN (R 4.0.0)
##  fBasics     * 3042.89.1 2020-03-07 [1] CRAN (R 4.0.2)
##  fs            1.4.1     2020-04-04 [1] CRAN (R 4.0.0)
##  generics      0.0.2     2018-11-29 [1] CRAN (R 4.0.0)
##  ggplot2     * 3.3.0     2020-03-05 [1] CRAN (R 4.0.0)
##  glue          1.4.2     2020-08-27 [1] CRAN (R 4.0.2)
##  gtable        0.3.0     2019-03-25 [1] CRAN (R 4.0.0)
##  htmltools     0.5.0     2020-06-16 [1] CRAN (R 4.0.2)
##  htmlwidgets   1.5.2     2020-10-03 [1] CRAN (R 4.0.2)
##  httr          1.4.2     2020-07-20 [1] CRAN (R 4.0.2)
##  jsonlite      1.7.1     2020-09-07 [1] CRAN (R 4.0.2)
##  knitr         1.30      2020-09-22 [1] CRAN (R 4.0.0)
##  lattice     * 0.20-41   2020-04-02 [1] CRAN (R 4.0.0)
##  lazyeval      0.2.2     2019-03-15 [1] CRAN (R 4.0.0)
##  lifecycle     0.2.0     2020-03-06 [1] CRAN (R 4.0.0)
##  lubridate   * 1.7.8     2020-04-06 [1] CRAN (R 4.0.0)
##  magrittr    * 1.5       2014-11-22 [1] CRAN (R 4.0.0)
##  memoise       1.1.0     2017-04-21 [1] CRAN (R 4.0.0)
##  mnormt        1.5-7     2020-04-30 [1] CRAN (R 4.0.0)
##  munsell       0.5.0     2018-06-12 [1] CRAN (R 4.0.0)
##  nlme          3.1-147   2020-04-13 [1] CRAN (R 4.0.0)
##  openxlsx    * 4.1.5     2020-05-06 [1] CRAN (R 4.0.0)
##  pillar        1.4.6     2020-07-10 [1] CRAN (R 4.0.2)
##  pkgbuild      1.1.0     2020-07-13 [1] CRAN (R 4.0.2)
##  pkgconfig     2.0.3     2019-09-22 [1] CRAN (R 4.0.0)
##  pkgload       1.1.0     2020-05-29 [1] CRAN (R 4.0.2)
##  plotly      * 4.9.2.1   2020-04-04 [1] CRAN (R 4.0.2)
##  plyr        * 1.8.6     2020-03-03 [1] CRAN (R 4.0.0)
##  prettyunits   1.1.1     2020-01-24 [1] CRAN (R 4.0.0)
##  pROC        * 1.16.2    2020-03-19 [1] CRAN (R 4.0.0)
##  processx      3.4.4     2020-09-03 [1] CRAN (R 4.0.2)
##  ps            1.4.0     2020-10-07 [1] CRAN (R 4.0.2)
##  psych       * 1.9.12.31 2020-01-08 [1] CRAN (R 4.0.0)
##  purrr       * 0.3.4     2020-04-17 [1] CRAN (R 4.0.0)
##  R6            2.5.0     2020-10-28 [1] CRAN (R 4.0.0)
##  Rcpp          1.0.5.4   2020-11-05 [1] local         
##  readxl      * 1.3.1     2019-03-13 [1] CRAN (R 4.0.0)
##  remotes       2.1.1     2020-02-15 [1] CRAN (R 4.0.0)
##  reshape     * 0.8.8     2018-10-23 [1] CRAN (R 4.0.0)
##  reshape2    * 1.4.4     2020-04-09 [1] CRAN (R 4.0.0)
##  rlang         0.4.8     2020-10-08 [1] CRAN (R 4.0.2)
##  rmarkdown     2.5       2020-10-21 [1] CRAN (R 4.0.0)
##  ROCR        * 1.0-11    2020-05-02 [1] CRAN (R 4.0.0)
##  rprojroot     1.3-2     2018-01-03 [1] CRAN (R 4.0.0)
##  rstudioapi    0.11      2020-02-07 [1] CRAN (R 4.0.0)
##  scales        1.1.1     2020-05-11 [1] CRAN (R 4.0.0)
##  sessioninfo   1.1.1     2018-11-05 [1] CRAN (R 4.0.0)
##  spatial       7.3-11    2015-08-30 [1] CRAN (R 4.0.0)
##  stringi       1.5.3     2020-09-09 [1] CRAN (R 4.0.2)
##  stringr     * 1.4.0     2019-02-10 [1] CRAN (R 4.0.0)
##  testthat      2.3.2     2020-03-02 [1] CRAN (R 4.0.0)
##  tibble        3.0.4     2020-10-12 [1] CRAN (R 4.0.2)
##  tidyr       * 1.1.0     2020-05-20 [1] CRAN (R 4.0.0)
##  tidyselect    1.1.0     2020-05-11 [1] CRAN (R 4.0.0)
##  timeDate    * 3043.102  2018-02-21 [1] CRAN (R 4.0.0)
##  timeSeries  * 3062.100  2020-01-24 [1] CRAN (R 4.0.2)
##  usethis       1.6.1     2020-04-29 [1] CRAN (R 4.0.0)
##  vctrs         0.3.4     2020-08-29 [1] CRAN (R 4.0.2)
##  viridisLite   0.3.0     2018-02-01 [1] CRAN (R 4.0.0)
##  withr         2.3.0     2020-09-22 [1] CRAN (R 4.0.2)
##  xfun          0.18      2020-09-29 [1] CRAN (R 4.0.2)
##  yaml          2.2.1     2020-02-01 [1] CRAN (R 4.0.0)
##  zip           2.0.4     2019-09-01 [1] CRAN (R 4.0.0)
##  zoo         * 1.8-8     2020-05-02 [1] CRAN (R 4.0.2)
## 
## [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library