forked from perlatex/R_for_Data_Science
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bayesian_intro_stan.Rmd
56 lines (32 loc) · 1.73 KB
/
bayesian_intro_stan.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Stan入门 {#bayesian-intro-stan}
相比于传统的方法来说,[Stan](https://mc-stan.org/)建模具有更好的可操作性、透明性和可解释性。本周开始,我们将开始学习贝叶斯数据分析,希望通过一些案例,让大家了解Stan的强大和价值。根据我有限的学习经验,采用code first 教学。
## R4.1配置方法
- 安装 [Rtools4.0](https://cran.r-project.org/bin/windows/Rtools/)到`C`盘
- 添加系统路径(电脑 - 属性 - 高级系统设置 - 环境变量 - 系统变量 - Path)
- `C:\rtools40`
- `C:\rtools40\mingw64\bin`
- `C:\rtools40\usr\bin`
- [配置](https://github.com/stan-dev/rstan/wiki/Configuring-C---Toolchain-for-Windows)
```{r, eval=FALSE}
writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")
```
- [安装rstan宏包](https://mc-stan.org/r-packages/)
```{r, eval=FALSE}
remove.packages(c("rstan", "StanHeaders"))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages(c("tidybayes", "bayesplot"))
```
## R4.2配置方法
- 安装 [Rtools42](https://cran.r-project.org/bin/windows/Rtools/rtools42/rtools.html)到`C`盘,推荐使用它默认的路径
- [安装rstan宏包](https://mc-stan.org/r-packages/)
```{r, eval=FALSE}
remove.packages(c("rstan", "StanHeaders"))
install.packages(c("rstan", "StanHeaders"), repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages(c("tidybayes", "bayesplot"))
```
## 遇到问题,请参考
- <https://mc-stan.org/r-packages/>
- <https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started>
```{r, echo = F, message = F, warning = F, results = "hide"}
pacman::p_unload(pacman::p_loaded(), character.only = TRUE)
```