bayes.student_t: Bayesian inference to estimate the parameters of student's t...

Description Usage Arguments Details See Also Examples

View source: R/bayes.student_t.R

Description

Bayesian inference to estimate the parameters of student's t distribution.

An example of student's t distirbution:

y ~ student_t( nu , mu , sigma )

nu, mu and sigma will be estimated via bayesian inference.

Deprecated and will be removed in future release, so use best.student_t instead.

Usage

1
bayes.student_t(vals, stanDso, ...)

Arguments

vals

A vector of metric values assumed to be generated from student's t distirbution.

stanDso

An object of class stanmodel.

...

Parameters passed to sampling(...) in package rstan.

Details

Estimate student's t distribution via Bayesian statistics provided by rstan package.

Please refer to: Stan-Ymet-Xnom1grp-Mrobust.R and Stan-Ymet-Xnom1grp-Mrobust-Example.R Accompanies the book: Kruschke, J. K. (2014). Doing Bayesian Data Analysis: A Tutorial with R and JAGS, 2nd Edition. Academic Press / Elsevier.

See Also

...

Examples

 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
library(lxctk)

## Step 1: compile the model
library(rstan)

# Translate to C++ and compile to DSO. This will take a few mins. Select one of the model_code.
model_code <- student_t_distribution_model()
stanDso <- stan_model( model_code=model_code ) 
## save(stanDso, file='stanDso.RData')  ## For later use

## If you have already had a stanmodel object stanDso saved as a RData file, 
## e.g. stanDso.RData, just load in R with load("stanDso.RData").

## Step 2: running an example
##rstan_options(auto_write = TRUE)
##options(mc.cores = 4)

x <- rt(1000, df=1)
fit <- bayes.student_t(x, stanDso)

## Important notes:
## If bayes.student_t was run in a for-loop (e.g. >128), there will be ERROR:
## "all connections are in use Stan model  does not contain samples."
## Because "A maximum of 128 connections can be allocated..." (?close.connection)
##+for more info. In this case, we need to close connections by hand. For example:

## for (i in 1000)
## {
##	  fit <- bayes.student_t(...)
##	  showConnections(all=TRUE) or ## print(showConnections(all=TRUE))
## }

lixiangchun/lxctk documentation built on May 21, 2019, 6:44 a.m.