楼主: oliyiyi
5680 62

Bayesian Statistics with Stan [推广有奖]

11
oliyiyi 发表于 2019-1-10 07:38:30 |只看作者 |坛友微信交流群
Appealing features of Bayesian inference
Here are some reasons we like to use Bayesian methods:

Integration of data and prior information

Quantification of uncertainty, including probabilistic predictions

Ability to pipe inference directly into decision analysis

Ability to handle uncertainty in large numbers of parameters

使用道具

12
oliyiyi 发表于 2019-1-10 07:39:07 |只看作者 |坛友微信交流群
It is said that the most important aspect of a statistical analysis is not what you do with the data, it’s what data you use. A key advantage of modern statistical methods (including Bayesian methods but also various non-Bayesian or semi-Bayesian approaches in machine learning) is that they allow you to incorporate different sorts of information into your analysis.

使用道具

13
oliyiyi 发表于 2019-1-11 07:38:12 |只看作者 |坛友微信交流群
RStan is the R interface to Stan. For more information on Stan and its modeling language visit the Stan website at http://mc-stan.org/

使用道具

14
oliyiyi 发表于 2019-1-11 07:39:07 |只看作者 |坛友微信交流群
Almost all install instructions below are for the aforementioned version of RStan, which requires that you have R version 3.4.0 or later. If necessary you can install the latest version of R from here.

In addition, we strongly recommend that you use RStudio version 1.2.x or later because it has great support for Stan.

使用道具

15
oliyiyi 发表于 2019-1-11 07:40:41 |只看作者 |坛友微信交流群
Installation of RStan
To be on the safe side, it is sometimes necessary to remove any existing RStan via

remove.packages("rstan")
if (file.exists(".RData")) file.remove(".RData")
Then, restart R.

In most cases, you can simply type (exactly like this)

install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
However, if you use Linux or if getOption("pkgType") has been set to "source" or if R asks you whether you want to install the latest version of RStan from source, then go to the corresponding page for Windows, Mac, or Linux.

使用道具

16
oliyiyi 发表于 2019-1-11 07:41:34 |只看作者 |坛友微信交流群
Checking the C++ Toolchain
In RStudio (preferably) or otherwise in R, execute once

pkgbuild::has_build_tools(debug = TRUE)
to check your C++ toolchain using the pkgbuild package that gets installed when you install RStan. If this line ultimately returns TRUE, then your C++ toolchain is properly installed and you can jump to the next section.

Otherwise,

If you use Windows and RStudio (recommended), a pop-up will appear asking if you want to install Rtools. Click Yes and wait until the installation is finished.
If you use Windows but not RStudio, a message will appear in the R console telling you to install Rtools. Further information to download and install rtools may be helpful, but you do NOT ordinarily need to continue to the section titled "Installing RStan from source".
If you use a Mac, a link will appear but do not click on it. Instead go here
If you use Linux (including Windows Subsystem for Linux), then go here.
If you follow the above instructions but are not successful you can get help from the Stan Discourse Forum but be sure to tell us what your operating system is, whether you use RStudio, and what is the output when you try the above.

使用道具

17
oliyiyi 发表于 2019-1-11 07:46:45 |只看作者 |坛友微信交流群
Configuration of the C++ Toolchain
This step is optional, but it can result in compiled Stan programs that execute much faster than they otherwise would. Simply paste the following into R once

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, ifelse(.Platform$OS.type == "windows", "Makevars.win", "Makevars"))
if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS=-O3 -march=native -mtune=native",
    if( grepl("^darwin", R.version$os)) "CXX14FLAGS += -arch x86_64 -ftemplate-depth-256" else
    if (.Platform$OS.type == "windows") "CXX11FLAGS=-O3 -march=native -mtune=native" else
    "CXX14FLAGS += -fPIC",
    file = M, sep = "\n", append = TRUE)

使用道具

18
oliyiyi 发表于 2019-1-11 07:47:13 |只看作者 |坛友微信交流群
How to Use RStan
The rest of this document assumes that you have already installed RStan by following the instructions above.

Loading the package
The package name is rstan (all lowercase), so we start by executing

library("rstan") # observe startup messages
As the startup message says, if you are using rstan locally on a multicore machine and have plenty of RAM to estimate your model in parallel, at this point execute

options(mc.cores = parallel::detectCores())
In addition, you should follow the second startup message that says to execute

rstan_options(auto_write = TRUE)
which allows you to automatically save a bare version of a compiled Stan program to the hard disk so that it does not need to be recompiled (unless you change it).

Finally, if you use Windows, there will be a third startup message saying to execute

Sys.setenv(LOCAL_CPPFLAGS = '-march=native')
which is not necessary if you followed the C++ toolchain configuration advice in the previous section.

使用道具

19
oliyiyi 发表于 2019-1-11 07:52:12 |只看作者 |坛友微信交流群
How to Use RStan
The rest of this document assumes that you have already installed RStan by following the instructions above.

Loading the package
The package name is rstan (all lowercase), so we start by executing

library("rstan") # observe startup messages
As the startup message says, if you are using rstan locally on a multicore machine and have plenty of RAM to estimate your model in parallel, at this point execute

options(mc.cores = parallel::detectCores())
In addition, you should follow the second startup message that says to execute

rstan_options(auto_write = TRUE)
which allows you to automatically save a bare version of a compiled Stan program to the hard disk so that it does not need to be recompiled (unless you change it).

Finally, if you use Windows, there will be a third startup message saying to execute

Sys.setenv(LOCAL_CPPFLAGS = '-march=native')
which is not necessary if you followed the C++ toolchain configuration advice in the previous section.

使用道具

20
oliyiyi 发表于 2019-1-11 08:09:09 |只看作者 |坛友微信交流群
How to Use RStan
The rest of this document assumes that you have already installed RStan by following the instructions above.

Loading the package
The package name is rstan (all lowercase), so we start by executing

library("rstan") # observe startup messages
As the startup message says, if you are using rstan locally on a multicore machine and have plenty of RAM to estimate your model in parallel, at this point execute

options(mc.cores = parallel::detectCores())
In addition, you should follow the second startup message that says to execute

rstan_options(auto_write = TRUE)
which allows you to automatically save a bare version of a compiled Stan program to the hard disk so that it does not need to be recompiled (unless you change it).

Finally, if you use Windows, there will be a third startup message saying to execute

Sys.setenv(LOCAL_CPPFLAGS = '-march=native')
which is not necessary if you followed the C++ toolchain configuration advice in the previous section.

使用道具

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

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-26 23:26