Rでベイズ統計学
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
SIZE(25){COLOR(red){Rでベイズ統計学}}
//written by 蓮見亮 10/10/2005
筆者は計量経済学が専攻なので、それ以外の分野の方のフォローを期待します。
#contents
~
*ベイズ統計学とは? [#zb04fab6]
統計的推論にベイズの定理を使う方法をいいます。
方法に一貫性があること、柔軟なモデルに対応できること、一般に"事前分布"を指定する必要があることなどの特色があります。
より詳しくは、[[松原先生のサイト:http://www.qmss.jp/appstat/contents/bayes/default.htm]]を参照してください。
*パッケージの一括インストール [#nf20f2fb]
詳しくは [[CRAN Task View]] (一般化モデルのあてはめ、特定のモデルおよび手法、事後推定ツール、学習ベイジアン統計学、他のサンプリングエンジンとRとのリンクの5分類でまとめている)を参照していただきたいが、簡単には、
install.packages("ctv")
library(ctv)
install.views("Bayesian")
で、必要なものはほぼすべて入ります。
個別のパッケージについては、
-[[CRAN Task View: Bayesian Inference:http://cran.r-project.org/web/views/Bayesian.html]]
を参照されたい。
**詳細 [#c3492c08]
-bqtl: ベイジアン QTL マッピング用の道具集
-BsMD: ベイズの篩及びモデル判別
//Bayes Screening and Model Discrimination
-boa: Bayesian Output Analysis Program (BOA) for MCMC
// Bayesian analysis in specific fields
-survBayes: Fits a proportional hazards model to time to event data by a Bayesian approach
-bayesm: Bayesian Inference for Marketing/Micro-econometrics
[[bayesmパッケージ(マーケティング/マイクロ計量経済学のベイズ推定)中のオブジェクト一覧]]
-eco: R Package for Fitting Bayesian Models of Ecological Inference in 2 x 2 Tables
-evdbayes: 極値理論のベイズ分析
-BMA: Bayesian Model Averaging
-MSBVAR: Bayesian Vector Autoregression Models, Impulse Responses and Fore
-BACCO: Bundle of emulator, calibrator Bayesian analysis of computer code software
-Zelig:[[Bayesian Multinomial Logistic Regression, Bayesian Normal Linear Regression, Bayesian Ordered Probit Regression, Bayesian Poisson Regression, Bayesian Probit Regression, Bayesian Linear Regression for a Censored Dependent Variable:http://gking.harvard.edu/zelig/docs/Models_Zelig_Can.html]]
-e1071:naive Bayes classifier
-MNP:マルコフ連鎖モンテカルロ経由のベイズ多項プロビットモデル
-tgp: Bayesian treed Gaussian process models
-msgcop: Semiparametric Bayesian Gaussian copula estimation
// Mixture modelling
-bayesmix: ベイズ混合モデリング用 R パッケージ
//-bayesmix: An R package for Bayesian Mixture Modeling
-vabayelMix: Variational Bayesian Mixture Model
// MCMC
-mcmc: Markov Chain Monte Carlo
-MCMCpack: Markov chain Monte Carlo (MCMC) Package
-elrm: Exact Logistic Regression via MCMC
//Bayesian Networks
-deal: Learning Bayesian Networks with Mixed Variables
//hierarchical spatial modelling
-[[spBayes:http://blue.fr.umn.edu/spatialBayes/]]
階層型空間モデリングパッケージ
--[[spBayes (単変量・多変量統計空間モデリング) パッケージ中のオブジェクト一覧]]
//Bayesian analysis of item-response theory (IRT) models
-pscl: Political Science Computational Laboratory, Stanford University
-bcp: Bayesian Change Point
--[[bcp(ベイジアン変化点)パッケージ中のオブジェクト一覧]]
-[[JAGS]]ギブス抽出法を用いたベイズ階層モデルの分析プログラム
-RJaCGH: CGH 配列解析のための Reversible Jump MCMC.
-MasterBayes: ML and MCMC Methods for Pedigree Reconstruction and Analysis
-BayHaz: R Functions for Bayesian Hazard Rate Estimation
-sbgcop: Semiparametric Bayesian Gaussian copula estimation
-G1DBN: 動的ベイズネットワーク推定実行パッケージ
//A package performing Dynamic Bayesian Network inference
-DPpackage: Bayesian Nonparametric and Semiparametric
-vbmp: 変分ベイズ多項プロビット回帰
-bnlearn: ベイズネットワーク構造学習
//Bayesian network structure learning
-predbayescor: Classification rule based on Bayesian naive Bayes models with feature selection bias corrected
-predmixcor: Classification rule based on Bayesian mixture models with feature selection bias corrected
-geoR(地球統計用データ分析関数)パッケージ
ベイズ分析対応の関数がある
-ramps: RAMPS を
使ったベイズ地球統計モデリング(Bayesian Geostatistical Modeling with RAMPS )
-BAYSTAR: On Bayesian analysis of Threshold autoregressive model (BAYSTAR)
-bayescount: Bayesian analysis of count distributions with JAGS
-cobs: COBS -- 拘束条件付きの B-スプライン (Sparse matrix ベース)
-pscl: Political Science Computational Laboratory, Stanford University
--Bayesian analysis of item-response theory (IRT) models
-BPHO: 工事の相互作用についてのベイズ予測
//Bayesian Prediction with High-order Interactions
-siar: R での安定アイソトープ分析(Stable Isotope Analysis in R)
--using Bayesian model
-mombf: Moment and Inverse Moment Bayes factors
-bspec: Bayesian spectral inference
-rjags: MCMC を用いたベイズグラフィカルモデル
-runjags: Run Bayesian MCMC Models in the BUGS syntax from Within R
-ensembleBMA: アンサンブルおよびベイズモデル平均化を使った確率的予測
[[アンサンブル予測:http://www.jma.go.jp/jma/kishou/know/kisetsu_riyou/glossary/ensenble.html]]
-dlm: Bayesian and Likelihood Analysis of Dynamic Linear Models
-bayesGARCH: Bayesian Estimation of the GARCH(1,1) Model with Student's t Innovations
-BaM: Functions and datasets for books by Jeff Gill
Books is "Bayesian Methods: A Social and Behavioral Sciences Approach, Second Edition published by CRC Press, 2007"
-bark: ベイズ加法回帰カーネル Bayesian Additive Regresssion Kernels
-rv: Simulation-based random variable object class in R
-SimpleTable: Bayesian Inference and Sensitivity Analysis for Causal Effects from 2 x 2 and 2 x 2 x K Tables in the Presence of Unmeasured Confounding
-glmmBUGS: WinBUGS をもちいた一般化線形混合モデル
-Bolstad: Bolstad の関数
-bayesclust: Tests/Searches for significant clusters in genetic data
-BAS: Bayesian Model Averaging using Bayesian Adaptive Sampling
-BayesX: R Utilities Accompanying the Software Package BayesX
-amei: Adaptive Management of Epidemiological Interventions
-scapeMCMC: MCMC 診断プロット
//MCMC diagnostic plots
-BayesTree: 木に基づくモデルのベイズ手法
//Bayesian Methods for Tree Based Models
-spatcounts: Spatial count regression (MCMC を使用)
-HWEBayes: Bayesian investigation of Hardy-Weinberg Equilibrium via estimation and testing
-emulator: Bayesian emulation of computer programs
-WMCapacity: GUI implementing Bayesian working memory models
-BayesQTLBIC: Bayesian multi-locus QTL analysis based on the BIC criterion
-Bolstad2: Bolstad functions
-arm: 回帰及びマルチレベル/階層モデルを使ったデータ分析
// Data Analysis Using Regression and Multilevel/Hierarchical Models
-CORElearn: CORElearn - classification, regression, feature evaluation and ordinal evaluation
-Bergm: Bayesian inference for exponential random graph models
-cudaBayesreg: fMRI データ分析用マルチレベルモデルの CUDA 並列実装
//CUDA Parallel Implementation of a Bayesian Multilevel Model for fMRI Data Analysis
-mixAK: Mixture of methods including mixtures
-hergm: Hierarchical Exponential-Family Random Graph Models
-B2Z: Bayesian Two-Zone Model
-catnet: catnet: Categorical Bayesian Network Inference
-BayesPanel: Bayesian Methods for Panel Data Modeling and Inference
-GSM: Gamma Shape Mixture
-BTSPAS: Bayesian Time-Strat. Population Analysis
-splinesurv: Nonparametric bayesian survival analysis
-mugnet: Mixture of Gaussian Bayesian Network Model
-bfp: Bayesian Fractional Polynomials
-MCMChybridGP: Hybrid Markov chain Monte Carlo using Gaussian Processes
-Bchron: Bayesian chronologies via compound Poisson-Gamma process
-abc: Functions to perform Approximate Bayesian Computation (ABC) using simulated data
-bayesLife: Bayesian Projection of Life Expectancy
-bayesTFR: Bayesian Fertility Projection
-varSelectIP: Objective Bayes Model Selection
-HPbayes: Heligman Pollard mortality model parameter estimation using Bayesian Melding with Incremental Mixture Importance Sampling
-LaplacesDemon: Laplace's Demon: Software for Bayesian Inference
-BAMD: Bayesian Association Model for Genomic Data with Missing Covariates
-MISA: Bayesian Model Search and Multilevel Inference for SNP Association Studies
-monomvn: Estimation for multivariate normal and Student-t data with monotone missingness
-[[casper:https://r-forge.r-project.org/projects/casper/]]infers alternative splicing from high-throughput sequencing data both for known variants and de novo discovery.
-BCBCSF: Bias-corrected Bayesian Classification with Selected Features
-rriskBayes: Predefined Bayes models fitted with Markov chain Monte Carlo (MCMC) (related to the 'rrisk' project)
-JMbayes: Joint Modeling of Longitudinal and Time-to-Event Data under a Bayesian Approach
-sdnet: Soft Discretization-based Bayesian Network Inference
-[[bscr: Bayesian parametric and semi-parametric analyses for semi-competing risks data:http://cran.md.tsukuba.ac.jp/web/packages/bscr/]]
-[[spatialprobit: Spatial Probit Models:http://cran.rstudio.com/web/packages/spatialprobit/index.html]]
-[[gsbDesign: Group Sequential Bayes Design:http://cran.md.tsukuba.ac.jp/web/packages/gsbDesign/]]
-[[PReMiuM: Dirichlet Process Bayesian Clustering, Profile Regression:http://cran.md.tsukuba.ac.jp/web/packages/PReMiuM/]]
-[[Bayesian Statistics@R-Forge:https://r-forge.r-project.org/softwaremap/trove_list.php?form_cat=55]]
--[[BayesSDEmacroevolution:http://bayessdeevol.r-forge.r-project.org/]]
-[[tsbugs: Create time series BUGS models:http://cran.r-project.org/web/packages/tsbugs/index.html]]
--[[The tsbugs package for R:http://gjabel.wordpress.com/2013/01/15/tsbugs-package/]]
-[[CRAN Task View: Bayesian Inference:http://cran.r-project.org/src/contrib/Views/Bayesian.html]] ・・・各パッケージの分類と要約
--モデルのあてはめ(Bayesian packages for general model fitting), 特定のモデル又は手法(Bayesian packages for specific models or methods),推定?(Post-estimation tools),学習ベイズ統計(Packages for learning Bayesian statistics),Rとのリンク(Packages that link R to other sampling engines) の5つで分類している
まずは MCMCpack を使うのが無難です。
BUGS/WinBUGS というソフトを使えば、より広範囲のモデルについて推定可能です。
BUGS/WinBUGS は R から呼び出し可能です。
COLOR(red){SIZE(20){参考}}
+[[coda(マルコフ連鎖モンテカルロ(MCMC)シミュレーションについての出力の分析および診断)パッケージ中のオブジェクト一覧]]
+[[R2WinBUGS(R より WinBUGS および OpenBUGS の実行)パッケージ中のオブジェクト一覧]]
+[[OpenBUGS]]
*MCMCpack [#lc5208c5]
R のベイズ分析に関するライブラリの中では,もっとも汎用的なものです.
[[MCMCpackパッケージ(マルコフ連鎖モンテカルロ)中のオブジェクト一覧]]
**実例(線形回帰モデル/OLSとの比較) [#jdea8a22]
Hayashi, Fumio. Econometrics. Princeton University Press, 2000. Ch. 1 の例。
Elec<-read.table("http://www.rhasumi.net/data/econometrics/nerlove.txt")
LTC<-log(Elec[,1]); LQ <- log(Elec[,2]); LPL <- log(Elec[,3]);
LPF <- log(Elec[,4]); LPK <- log(Elec[,5])
#OLS 推定 Model (1.7.4)
result_b<-lm(LTC~LQ+LPL+LPF+LPK)
summary(result_b)
>summary(result_b) #一部略
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -3.52650 1.77437 -1.987 0.0488 *
LQ 0.72039 0.01747 41.244 < 2e-16 ***
LPL 0.43634 0.29105 1.499 0.1361
LPF 0.42652 0.10037 4.249 3.89e-05 ***
LPK -0.21989 0.33943 -0.648 0.5182
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#MCMC
library(MCMCpack)
posterior <- MCMCregress(LTC~LQ+LPL+LPF+LPK, verbose=1000)
plot(posterior)
raftery.diag(posterior)
summary(posterior)
> summary(posterior)#一部略
1. Empirical mean and standard deviation for each variable,
plus standard error of the mean:
Mean SD Naive SE Time-series SE
(Intercept) -3.5398 1.79372 0.0179372 0.0193031
LQ 0.7205 0.01771 0.0001771 0.0001730
LPL 0.4389 0.29323 0.0029323 0.0023149
LPF 0.4269 0.10194 0.0010194 0.0010259
LPK -0.2180 0.34276 0.0034276 0.0037750
sigma2 0.1564 0.01906 0.0001906 0.0001705
この場合大差ないことが分かると思います.
* bayesm(Bayesian Inference for Marketing/Micro-econometrics) [#abbb0c92]
[[bayesmパッケージ中のオブジェクト一覧]]
*MCMCglmm: MCMC 一般化混合モデル [#gc0a7d64]
//MCMC Generalised Linear Mixed Models
*BUGS/WinBUGS [#xb8bd283]
BUGS はベイズ推定のためのパッケージソフトで、MCMC 法により事後分布の密度関数の計算を行います。
WinBUGS はその Windows 版です。
WinBUGS 自体は単体で使えますが、R から呼び出したほうが簡単です。
//谷村晋 2006年8月17日加筆
// UNIX/LINUX での BUGS の呼び出し方については、筆者が試していないので略([[OpenBUGS]]を参照)。
WinBUGSはwineを使えばLinux上でも動作します。wine経由のWinBUGSもRから呼び出すことができます。
**インストール [#p81a1dbf]
WinBUGS は以下からダウンロードできます。WinBUGS の機能をすべて使うには、登録が必要です(無償)。
[[BUGS Project:http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/contents.shtml]]のページ
インストールが終わって、BUGS のコードも借りてくれば、R さえ使えれば WinBUGS について何も知らなくても使えます。
BUGSのコードは、例えば、
Lncaster, Tony. An Intoroduction to Modern Bayesian Econometrics. Blackwell, 2004.
にあります。
//谷村晋 2006年8月17日加筆
Linuxへのインストールは、Windowsと同様です。wineが正しく設定してあればWinBUGSをダウンロードするときにそのままwineでWinBUGSのインストーラを起動することができます。ダウンロード時にディスクに保存せずにそのままインストールした方が楽でしょう。
Rの側のパッケージは"R2WinBUGS"または"rbugs"です。"rbugs"はLinux上での利用を想定されたものでLinBUGS(デフォルト)/OpenBUGS/wine経由のWinBUGSをサポートしています。Linuxでは"rbugs"以外にWinBUGSと連携するためのパッケージがありませんでしたが、今のR2WinBUGSはwine経由のWinBUGSにも対応しているので、Linux上でも"R2WinBUGS"を使うことができます。ただし、[[1つバグ:http://finzi.psych.upenn.edu/R/Rhelp02a/archive/75440.html]]があり、wine経由のWinBUGSをR2WinBUGSから操作するには、bugs()の前に
WINEPATH <- "/usr/bin/winepath"
というおまじないが必要です。このバグは現在(2006年8月17日)も修正されていません。
"R2WinBUGS"を使う前に、
library(R2WinBUGS)
help(package="R2WinBUGS")
ここから、例をConsoleにコピーすれば、すぐにWinBUGSが走ります。
**線形回帰モデルの例 (数値例は仮設) [#m8529f09]
+model.fileの作成。BUGSのコードです。
"model.txt"などの名前でRのワーキング・ディレクトリに保存します。
model{
for(i in 1:n){y[i]~dnorm(mu[i],tau)
mu[i] <-alpha + beta1*x[i,1]+beta2*x[i,2]
}
alpha ~dnorm(0,0.0001)
beta1 ~dnorm(0,0.0001)
beta2 ~dnorm(0,0.0001)
tau ~dgamma(0.001, 0.001)
}
+データの作成(ノーテンションはmodel.fileにあわせます)
y <- c(1,3,3,3,5)
n <- NROW(y)
x1 <- c(1,2,3,5,5)
x2 <- c(2,3,1,5,2)
x <- matrix(c(x1,x2),ncol=2,nrow=5)
data <- list ("n", "y", "x")
+初期値の決定・結果を保存したいパラメータを指定
in1 <- list(alpha=0, beta1=0, beta2=0, tau=1)
in2 <- list(alpha=1, beta1=1, beta2=1, tau=1)
in3 <- list(alpha=2, beta1=2, beta2=2, tau=1)
inits <- list(in1,in2,in3)
parameters <- c("alpha", "beta1", "beta2", "tau")
+WinBUGSを走らせます。debug=TRUEにすれば、デバッグできます。
result.sim <- bugs(data, inits, parameters, model.file="model.txt",
n.chains = 3, n.iter = 1000, debug=FALSE,
bugs.directory = "c:/Program Files/WinBUGS14/",
working.directory = NULL)
+結果を見ます。例えば、
print(result.sim,digits=3)
result.sim$sims.list$beta1
--ちなみに、olsだと
result2.sim <- lm(y~x1+x2)
summary(result2.sim)
--パッケージ"MCMCpack"を使うと
line <- list ("y", "x")
result3.sim <- MCMCregress(y~x, data = parent.frame(), burnin = 1000, mcmc = 10000)
+本来は、このあとlibrary coda をつかってマルコフ連鎖の収束判定をするべきです。
*エラーとの戦い [#cb9c88fb]
//2213 加筆です。(2009/02/05)
-Permission denied 加筆者はVistaのUAC(ユーザーアカウント制御)解除でクリア(自己責任でお願いします。)
-educational version 対応パッチ?を[[WinBugsのページ:http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/register.shtml]]からおとしてください。
*パッケージソフトで対応できない場合 [#rf61bc64]
R の関数だけをつかって MCMC 法を実行するのは速度的に厳しいため、全体を C/C++ で書き、それを R から呼ぶという方法を推奨します。
詳しくは、[[Rから他言語利用]]を参照のこと。
*ベイズネットワーク [#kfed0448]
*[[Stan:http://mc-stan.org/]] [#x38e2b29]
-[[RStan:http://mc-stan.org/r-quickstart.html]]|
--[[RStan: Fast, multilevel Bayesian modeling in R:http://blog.revolutionanalytics.com/2012/08/rstan-fast-multilevel-bayesian-modeling-in-r.html]]
--[[Stan for Bayesian Analysis:http://www.r-bloggers.com/stan-for-bayesian-analysis/]]
--R: RStanをためす
---[[1:http://ito-hi.blog.so-net.ne.jp/2012-09-01]],[[2:http://ito-hi.blog.so-net.ne.jp/2012-09-02]],[[3:http://ito-hi.blog.so-net.ne.jp/2012-09-17]]
--[[RStudioでStanがi386のライブラリをよみにいくとき:http://ito-hi.blog.so-net.ne.jp/2012-11-02]]
*参考書 [#c5bca139]
+Koop, Gary. Bayesian Econometrics. Wiley, 2003.
+Lncaster, Tony. An Intoroduction to Modern Bayesian Econometrics. Blackwell, 2004.
+中妻照雄『ファイナンスのためのMCMC法によるベイズ分析』三菱経済研究所, 2003年
+[[和合肇編著『ベイズ計量経済分析』東洋経済新報社, 2005.:http://www.amazon.co.jp/%E3%83%99%E3%82%A4%E3%82%BA%E8%A8%88%E9%87%8F%E7%B5%8C%E6%B8%88%E5%88%86%E6%9E%90%E2%80%95%E3%83%9E%E3%83%AB%E3%82%B3%E3%83%95%E9%80%A3%E9%8E%96%E3%83%A2%E3%83%B3%E3%83%86%E3%82%AB%E3%83%AB%E3%83%AD%E6%B3%95%E3%81%A8%E3%81%9D%E3%81%AE%E5%BF%9C%E7%94%A8-%E5%92%8C%E5%90%88-%E8%82%87/dp/4492313397]]
+Williams, David. Weighing the Odds. Cambridge University Press, 2001.
+[[経済・経営のための統計学(2005, 有斐閣):http://www.amazon.co.jp/%E7%B5%8C%E6%B8%88%E3%83%BB%E7%B5%8C%E5%96%B6%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AE%E7%B5%B1%E8%A8%88%E5%AD%A6-%E6%9C%89%E6%96%90%E9%96%A3%E3%82%A2%E3%83%AB%E3%83%9E-%E7%89%A7-%E5%8E%9A%E5%BF%97/dp/4641122458]]
9章 ベイズ統計
+[[Bayesian Statistics and Marketing:http://gsbwww.uchicago.edu/fac/peter.rossi/research/bsm.html]] Greg Allenby, Rob McCulloch, Peter Rossi, 2005, John Wiley & Sons~
この本のDraftとRのコード。
+[[Bayesian Data Analysis, 2nd Ed.:http://www.crcpress.com/shopping_cart/products/product_detail.asp?sku=C388X&parent_id=&pc=]] Andrew Gelman, John B. Carlin, Hal S. Stern, Donald B. Rubin, 2003, Crc Pr I Llc.~
Appendix C が "Example of computation in R and Bugs"という題になっており,
そこにRのコードが書いてあります。
--[[Andrew Gelmanのサイト:http://www.stat.columbia.edu/~gelman/book/]]にPDFファイルがあります(『Appendix C from the second edition of Bayesian Data Analysis』).
+[[A Practical Approach to Computational Bayesian Statistics:http://www.amazon.co.jp/Bayesian-Core-Practical-Computational-Statistics/dp/0387389792/ref=sr_11_1/503-7622661-8431115]] Jean-Michel Marin, Christian P. Robert, 2007, Springer.
+[[Data Analysis Using Regression and Multilevel/Hierarchical Models:http://www.stat.columbia.edu/~gelman/arm/]] Andrew Gelman, Jennifer Hill, 2007, Cambridge University Press、このサイトにプログラム、データ、正誤表あり
+R News, Volume 5/2, November 2005
BMA の紹介
+[[R News, volume 6/1, issue 1:http://cran.r-project.org/doc/Rnews/Rnews_2006-1.pdf]]
ベイズ関連パッケージの特集
+[[Bayesian Computation with R (Use R) :http://www.amazon.co.jp/Bayesian-Computation-R-Use/dp/0387713840/ref=pd_ys_ir_all_7/249-8611663-8418753]] Albert, J., 2007,Springer. 著者作成の LearnBayes パッケージ(CRAN にあり)を利用
+[[Data Analysis Using Regression and Multilevel/Hierarchical Models:http://www.amazon.co.jp/dp/0521867061/ref=s9_asin_title_2/249-8611663-8418753?pf_rd_m=AN1VRQENFRJN5&pf_rd_s=center-2&pf_rd_r=1V4B4717C24TWQYJ2Q54&pf_rd_t=101&pf_rd_p=61605506&pf_rd_i=489986]] Andrew Gelman and Jennifer Hill, 2006, Cambridge Univ Pr. マルチレベル階層分析のハンドブック。R と WinBUGS を利用。
+[[『マルコフ連鎖モンテカルロ法』:http://www.asakura.co.jp/books/isbn/978-4-254-12697-6/]] 豊田秀樹 編著, 2007, 朝倉書店.
+[[Bayesian Disease Mapping: Hierarchical Modeling in Spatial Epidemiology:http://www.crcpress.com/shopping_cart/products/product_detail.asp?sku=C8407&isbn=9781584888406&parent_id=500&pc=]]
+[[Hierarchical Modeling and Analysis for Spatial Data:http://www.crcpress.com/shopping_cart/products/product_detail.asp?sku=C410X&isbn=9781584884101&parent_id=500&pc=]] GeoR
+[[Hierarchical Modeling and Analysis for Spatial Data(Monographs on Statistics & Applied Probability) 2nd Ed. :http://www.amazon.co.uk/dp/1439819173?tag=spatialanalys-21&camp=2202&creative=7754&linkCode=op1&creativeASIN=1439819173&adid=0GVNXGXR5H02PEFHNNQP&]], Sudipto Banerje, S., Gelfand, A. E., Carlin, B. P., 2011,CRC, pp. 608.
+『Rによるマーケティング・シミュレーション』
+ [[BAYESIAN METHODS: A Social and Behavioral Sciences Approach, Second Edition:http://www.crcpress.com/shopping_cart/products/product_detail.asp?sku=C5629&isbn=9781584885627&parent_id=501&pc=]] サポートパッケージ:BaM @ CRAN
+古谷知之著[[『ベイズ統計データ分析 ―R & WinBUGS― (統計ライブラリー)』:http://www.asakura.co.jp/books/isbn/978-4-254-12698-3/]],朝倉書店,2008.
+Bolstad, W.M. (2007):"Introduction to Bayesian Statistics", John Wiley & Sons ISBN 0-471-27020-2
+姜 興起 著(2010):[[『ベイズ統計データ解析』:http://www.kyoritsu-pub.co.jp/series/arudemanabu.html#3]]、共立出版
+安道知寛 著[[『ベイズ統計モデリング』:http://www.asakura.co.jp/books/isbn/978-4-254-12793-5/]],朝倉書店
+照井伸彦 著 :[[『Rによるベイズ統計分析』:http://www.asakura.co.jp/books/isbn/978-4-254-12812-3/]],朝倉書店
+[[Introduction to Probability Simulation and Gibbs Sampling with R:http://www.springer.com/statistics/statistical+theory+and+methods/book/978-0-387-40273-4]] Eric A., Trumbo, Bruce E.,2010, Springer.
+[[Bayesian Ideas and Data Analysis: An Introduction for Scientists and Statisticians:http://www.crcpress.com/product/isbn/9781439803547]], Christensen R., Johnson W. O., Branscum A. J., Hanson T. E., 2010, Chapman & Hall/CRC.
+[[Bayesian Model Selection and Statistical Modeling:http://www.crcpress.com/product/isbn/9781439836149]], Ando T., 2010, CRC press. [[サポートページ:http://labs.kbs.keio.ac.jp/andotomohiro/Bayesianbook.htm]]
+J.アルバート (著) 、石田 基広・石田 和枝 (共訳) (2010):[[Rで学ぶベイズ統計学入門:http://www.amazon.co.jp/dp/4431102388/]] シュプリンガー・ジャパン
+古谷知之著[[『Rによる空間データの統計分析』:http://www.asakura.co.jp/books/isbn/978-4-254-12815-4/]],朝倉書店,2011.
+Kruschke, J.:[[Doing Bayesian Data Analysis: A Tutorial Introduction with R and BUGS:http://www.amazon.co.jp/Doing-Bayesian-Data-Analysis-Introduction/dp/0123814855]], Academic Press, 2010
+Efron, Bradley:[[Large-Scale Inference: Empirical Bayes Methods for Estimation, Testing, and Prediction (Institute of Mathematical Statistics Monographs) :http://www.amazon.co.jp/Large-Scale-Inference-Estimation-Prediction-Mathematical/dp/0521192498]], Cambridge University Press,2010.
+久保 拓弥著:[[データ解析のための統計モデリング入門 ―― 一般化線形モデル・階層ベイズモデル・MCMC ――:http://www.iwanami.co.jp/cgi-bin/isearch?isbn=ISBN978-4-00-006973-1]], 岩波書店,2012.
+Yau, C.:[[R Tutorial with Bayesian Statistics Using OpenBUGS:http://www.amazon.com/Tutorial-Bayesian-Statistics-OpenBUGS-ebook/dp/B006ZP4SKW/ref=sr_1_1?ie=UTF8&qid=1350884313&sr=8-1&keywords=R+Tutorial+with+Bayesian+Statistics+Using+OpenBUGS]], Amazon Digital Services, Inc., 2012.
+[[Bayesian Inference Using OpenBUGS:http://www.r-tutor.com/bayesian-statistics/openbugs]]
+[[The BUGS Book: A Practical Introduction to Bayesian Analysis:http://www.crcpress.com/product/isbn/9781584888499]],Chapman & Hall/CRC , 2012. [[サポートサイト:http://www.mrc-bsu.cam.ac.uk/bugs/thebugsbook/]]
+G.ペトリス ・S.ペトローネ ・P.カンパニョーリ 著/和合肇 監訳/萩原淳一郎 訳:[[Rによるベイジアン動的線型モデル:http://www.asakura.co.jp/books/isbn/978-4-254-12796-6/]],朝倉書店,2014.
*関連サイト [#r01ed898]
-[[ベイズ統計学のページ:http://web.mita.keio.ac.jp/~ds064410/wiki.cgi?page=%A5%D9%A5%A4%A5%BA%C5%FD%B7%D7%B3%D8%A4%CE%A5%DA%A1%BC%A5%B8]]
-[[Bayes:http://www.rhasumi.net/wiki/wiki.cgi?page=Bayes]]
-[[生態学のデータ解析 - ベイズ統計 & MCMC:http://hosho.ees.hokudai.ac.jp/~kubo/ce/BayesianMcmc.html]]
-空間生存分析
-空間パネル分析
-[[Bayesian Model Averaging (BMA) with uncertain Spatial Effects:http://www.r-bloggers.com/bayesian-model-averaging-bma-with-uncertain-spatial-effects/]] spdep + BMA
-[[OBANSoft: integrated software for Bayesian statistics and high performance computing with R:http://www.warwick.ac.uk/statsdept/user-2011/TalkSlides/Contributed/16Aug_1115_FocusI_3-HighPerfComp_4-Quesada.pdf]]
-[[General Bayesian estimation using MHadaptive:http://www.r-bloggers.com/general-bayesian-estimation-using-mhadaptive/]]
-[[maps2winbugsplugin:http://code.google.com/p/maps2winbugsplugin/]] maps2WinBUGS plugin for Quantum GIS
-[[線形混合モデル/階層線形モデル/マルチレベル分析について:http://mizumot.com/lablog/?p=179]]
-[[Let's Do Some Hierarchical Bayes Choice Modeling in R!:http://joelcadwell.blogspot.jp/2013/03/lets-do-some-hierarchical-bayes-choice.html]]
-[[BayesComp:http://bayescomp.wikidot.com]]
--[[BayesComp homepage:http://xianblog.wordpress.com/2013/04/15/bayescomp-homepage/]]
-[[Bayesian computational tools:http://xianblog.wordpress.com/2013/06/18/bayesian-computational-tools-2/]]
-[[R and Bayesian Statistics:http://blog.revolutionanalytics.com/2013/11/r-and-bayesian-statistics.html]]
-[[Easy Laplace Approximation of Bayesian Models in R:http://www.sumsar.net/blog/2013/06/three-ways-to-run-bayesian-models-in-r/]]
*コメント [#sf91b9f2]
- RというよりWinbugs本かもしれないですが、[[カエル本の訳本:http://www.kyoritsu-pub.co.jp/kinkan/shosai/kin05678-7.html]]がでるのですね。 -- [[そう]] &new{2009-01-26 (月) 19:56:58};
#comment
終了行:
SIZE(25){COLOR(red){Rでベイズ統計学}}
//written by 蓮見亮 10/10/2005
筆者は計量経済学が専攻なので、それ以外の分野の方のフォローを期待します。
#contents
~
*ベイズ統計学とは? [#zb04fab6]
統計的推論にベイズの定理を使う方法をいいます。
方法に一貫性があること、柔軟なモデルに対応できること、一般に"事前分布"を指定する必要があることなどの特色があります。
より詳しくは、[[松原先生のサイト:http://www.qmss.jp/appstat/contents/bayes/default.htm]]を参照してください。
*パッケージの一括インストール [#nf20f2fb]
詳しくは [[CRAN Task View]] (一般化モデルのあてはめ、特定のモデルおよび手法、事後推定ツール、学習ベイジアン統計学、他のサンプリングエンジンとRとのリンクの5分類でまとめている)を参照していただきたいが、簡単には、
install.packages("ctv")
library(ctv)
install.views("Bayesian")
で、必要なものはほぼすべて入ります。
個別のパッケージについては、
-[[CRAN Task View: Bayesian Inference:http://cran.r-project.org/web/views/Bayesian.html]]
を参照されたい。
**詳細 [#c3492c08]
-bqtl: ベイジアン QTL マッピング用の道具集
-BsMD: ベイズの篩及びモデル判別
//Bayes Screening and Model Discrimination
-boa: Bayesian Output Analysis Program (BOA) for MCMC
// Bayesian analysis in specific fields
-survBayes: Fits a proportional hazards model to time to event data by a Bayesian approach
-bayesm: Bayesian Inference for Marketing/Micro-econometrics
[[bayesmパッケージ(マーケティング/マイクロ計量経済学のベイズ推定)中のオブジェクト一覧]]
-eco: R Package for Fitting Bayesian Models of Ecological Inference in 2 x 2 Tables
-evdbayes: 極値理論のベイズ分析
-BMA: Bayesian Model Averaging
-MSBVAR: Bayesian Vector Autoregression Models, Impulse Responses and Fore
-BACCO: Bundle of emulator, calibrator Bayesian analysis of computer code software
-Zelig:[[Bayesian Multinomial Logistic Regression, Bayesian Normal Linear Regression, Bayesian Ordered Probit Regression, Bayesian Poisson Regression, Bayesian Probit Regression, Bayesian Linear Regression for a Censored Dependent Variable:http://gking.harvard.edu/zelig/docs/Models_Zelig_Can.html]]
-e1071:naive Bayes classifier
-MNP:マルコフ連鎖モンテカルロ経由のベイズ多項プロビットモデル
-tgp: Bayesian treed Gaussian process models
-msgcop: Semiparametric Bayesian Gaussian copula estimation
// Mixture modelling
-bayesmix: ベイズ混合モデリング用 R パッケージ
//-bayesmix: An R package for Bayesian Mixture Modeling
-vabayelMix: Variational Bayesian Mixture Model
// MCMC
-mcmc: Markov Chain Monte Carlo
-MCMCpack: Markov chain Monte Carlo (MCMC) Package
-elrm: Exact Logistic Regression via MCMC
//Bayesian Networks
-deal: Learning Bayesian Networks with Mixed Variables
//hierarchical spatial modelling
-[[spBayes:http://blue.fr.umn.edu/spatialBayes/]]
階層型空間モデリングパッケージ
--[[spBayes (単変量・多変量統計空間モデリング) パッケージ中のオブジェクト一覧]]
//Bayesian analysis of item-response theory (IRT) models
-pscl: Political Science Computational Laboratory, Stanford University
-bcp: Bayesian Change Point
--[[bcp(ベイジアン変化点)パッケージ中のオブジェクト一覧]]
-[[JAGS]]ギブス抽出法を用いたベイズ階層モデルの分析プログラム
-RJaCGH: CGH 配列解析のための Reversible Jump MCMC.
-MasterBayes: ML and MCMC Methods for Pedigree Reconstruction and Analysis
-BayHaz: R Functions for Bayesian Hazard Rate Estimation
-sbgcop: Semiparametric Bayesian Gaussian copula estimation
-G1DBN: 動的ベイズネットワーク推定実行パッケージ
//A package performing Dynamic Bayesian Network inference
-DPpackage: Bayesian Nonparametric and Semiparametric
-vbmp: 変分ベイズ多項プロビット回帰
-bnlearn: ベイズネットワーク構造学習
//Bayesian network structure learning
-predbayescor: Classification rule based on Bayesian naive Bayes models with feature selection bias corrected
-predmixcor: Classification rule based on Bayesian mixture models with feature selection bias corrected
-geoR(地球統計用データ分析関数)パッケージ
ベイズ分析対応の関数がある
-ramps: RAMPS を
使ったベイズ地球統計モデリング(Bayesian Geostatistical Modeling with RAMPS )
-BAYSTAR: On Bayesian analysis of Threshold autoregressive model (BAYSTAR)
-bayescount: Bayesian analysis of count distributions with JAGS
-cobs: COBS -- 拘束条件付きの B-スプライン (Sparse matrix ベース)
-pscl: Political Science Computational Laboratory, Stanford University
--Bayesian analysis of item-response theory (IRT) models
-BPHO: 工事の相互作用についてのベイズ予測
//Bayesian Prediction with High-order Interactions
-siar: R での安定アイソトープ分析(Stable Isotope Analysis in R)
--using Bayesian model
-mombf: Moment and Inverse Moment Bayes factors
-bspec: Bayesian spectral inference
-rjags: MCMC を用いたベイズグラフィカルモデル
-runjags: Run Bayesian MCMC Models in the BUGS syntax from Within R
-ensembleBMA: アンサンブルおよびベイズモデル平均化を使った確率的予測
[[アンサンブル予測:http://www.jma.go.jp/jma/kishou/know/kisetsu_riyou/glossary/ensenble.html]]
-dlm: Bayesian and Likelihood Analysis of Dynamic Linear Models
-bayesGARCH: Bayesian Estimation of the GARCH(1,1) Model with Student's t Innovations
-BaM: Functions and datasets for books by Jeff Gill
Books is "Bayesian Methods: A Social and Behavioral Sciences Approach, Second Edition published by CRC Press, 2007"
-bark: ベイズ加法回帰カーネル Bayesian Additive Regresssion Kernels
-rv: Simulation-based random variable object class in R
-SimpleTable: Bayesian Inference and Sensitivity Analysis for Causal Effects from 2 x 2 and 2 x 2 x K Tables in the Presence of Unmeasured Confounding
-glmmBUGS: WinBUGS をもちいた一般化線形混合モデル
-Bolstad: Bolstad の関数
-bayesclust: Tests/Searches for significant clusters in genetic data
-BAS: Bayesian Model Averaging using Bayesian Adaptive Sampling
-BayesX: R Utilities Accompanying the Software Package BayesX
-amei: Adaptive Management of Epidemiological Interventions
-scapeMCMC: MCMC 診断プロット
//MCMC diagnostic plots
-BayesTree: 木に基づくモデルのベイズ手法
//Bayesian Methods for Tree Based Models
-spatcounts: Spatial count regression (MCMC を使用)
-HWEBayes: Bayesian investigation of Hardy-Weinberg Equilibrium via estimation and testing
-emulator: Bayesian emulation of computer programs
-WMCapacity: GUI implementing Bayesian working memory models
-BayesQTLBIC: Bayesian multi-locus QTL analysis based on the BIC criterion
-Bolstad2: Bolstad functions
-arm: 回帰及びマルチレベル/階層モデルを使ったデータ分析
// Data Analysis Using Regression and Multilevel/Hierarchical Models
-CORElearn: CORElearn - classification, regression, feature evaluation and ordinal evaluation
-Bergm: Bayesian inference for exponential random graph models
-cudaBayesreg: fMRI データ分析用マルチレベルモデルの CUDA 並列実装
//CUDA Parallel Implementation of a Bayesian Multilevel Model for fMRI Data Analysis
-mixAK: Mixture of methods including mixtures
-hergm: Hierarchical Exponential-Family Random Graph Models
-B2Z: Bayesian Two-Zone Model
-catnet: catnet: Categorical Bayesian Network Inference
-BayesPanel: Bayesian Methods for Panel Data Modeling and Inference
-GSM: Gamma Shape Mixture
-BTSPAS: Bayesian Time-Strat. Population Analysis
-splinesurv: Nonparametric bayesian survival analysis
-mugnet: Mixture of Gaussian Bayesian Network Model
-bfp: Bayesian Fractional Polynomials
-MCMChybridGP: Hybrid Markov chain Monte Carlo using Gaussian Processes
-Bchron: Bayesian chronologies via compound Poisson-Gamma process
-abc: Functions to perform Approximate Bayesian Computation (ABC) using simulated data
-bayesLife: Bayesian Projection of Life Expectancy
-bayesTFR: Bayesian Fertility Projection
-varSelectIP: Objective Bayes Model Selection
-HPbayes: Heligman Pollard mortality model parameter estimation using Bayesian Melding with Incremental Mixture Importance Sampling
-LaplacesDemon: Laplace's Demon: Software for Bayesian Inference
-BAMD: Bayesian Association Model for Genomic Data with Missing Covariates
-MISA: Bayesian Model Search and Multilevel Inference for SNP Association Studies
-monomvn: Estimation for multivariate normal and Student-t data with monotone missingness
-[[casper:https://r-forge.r-project.org/projects/casper/]]infers alternative splicing from high-throughput sequencing data both for known variants and de novo discovery.
-BCBCSF: Bias-corrected Bayesian Classification with Selected Features
-rriskBayes: Predefined Bayes models fitted with Markov chain Monte Carlo (MCMC) (related to the 'rrisk' project)
-JMbayes: Joint Modeling of Longitudinal and Time-to-Event Data under a Bayesian Approach
-sdnet: Soft Discretization-based Bayesian Network Inference
-[[bscr: Bayesian parametric and semi-parametric analyses for semi-competing risks data:http://cran.md.tsukuba.ac.jp/web/packages/bscr/]]
-[[spatialprobit: Spatial Probit Models:http://cran.rstudio.com/web/packages/spatialprobit/index.html]]
-[[gsbDesign: Group Sequential Bayes Design:http://cran.md.tsukuba.ac.jp/web/packages/gsbDesign/]]
-[[PReMiuM: Dirichlet Process Bayesian Clustering, Profile Regression:http://cran.md.tsukuba.ac.jp/web/packages/PReMiuM/]]
-[[Bayesian Statistics@R-Forge:https://r-forge.r-project.org/softwaremap/trove_list.php?form_cat=55]]
--[[BayesSDEmacroevolution:http://bayessdeevol.r-forge.r-project.org/]]
-[[tsbugs: Create time series BUGS models:http://cran.r-project.org/web/packages/tsbugs/index.html]]
--[[The tsbugs package for R:http://gjabel.wordpress.com/2013/01/15/tsbugs-package/]]
-[[CRAN Task View: Bayesian Inference:http://cran.r-project.org/src/contrib/Views/Bayesian.html]] ・・・各パッケージの分類と要約
--モデルのあてはめ(Bayesian packages for general model fitting), 特定のモデル又は手法(Bayesian packages for specific models or methods),推定?(Post-estimation tools),学習ベイズ統計(Packages for learning Bayesian statistics),Rとのリンク(Packages that link R to other sampling engines) の5つで分類している
まずは MCMCpack を使うのが無難です。
BUGS/WinBUGS というソフトを使えば、より広範囲のモデルについて推定可能です。
BUGS/WinBUGS は R から呼び出し可能です。
COLOR(red){SIZE(20){参考}}
+[[coda(マルコフ連鎖モンテカルロ(MCMC)シミュレーションについての出力の分析および診断)パッケージ中のオブジェクト一覧]]
+[[R2WinBUGS(R より WinBUGS および OpenBUGS の実行)パッケージ中のオブジェクト一覧]]
+[[OpenBUGS]]
*MCMCpack [#lc5208c5]
R のベイズ分析に関するライブラリの中では,もっとも汎用的なものです.
[[MCMCpackパッケージ(マルコフ連鎖モンテカルロ)中のオブジェクト一覧]]
**実例(線形回帰モデル/OLSとの比較) [#jdea8a22]
Hayashi, Fumio. Econometrics. Princeton University Press, 2000. Ch. 1 の例。
Elec<-read.table("http://www.rhasumi.net/data/econometrics/nerlove.txt")
LTC<-log(Elec[,1]); LQ <- log(Elec[,2]); LPL <- log(Elec[,3]);
LPF <- log(Elec[,4]); LPK <- log(Elec[,5])
#OLS 推定 Model (1.7.4)
result_b<-lm(LTC~LQ+LPL+LPF+LPK)
summary(result_b)
>summary(result_b) #一部略
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -3.52650 1.77437 -1.987 0.0488 *
LQ 0.72039 0.01747 41.244 < 2e-16 ***
LPL 0.43634 0.29105 1.499 0.1361
LPF 0.42652 0.10037 4.249 3.89e-05 ***
LPK -0.21989 0.33943 -0.648 0.5182
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#MCMC
library(MCMCpack)
posterior <- MCMCregress(LTC~LQ+LPL+LPF+LPK, verbose=1000)
plot(posterior)
raftery.diag(posterior)
summary(posterior)
> summary(posterior)#一部略
1. Empirical mean and standard deviation for each variable,
plus standard error of the mean:
Mean SD Naive SE Time-series SE
(Intercept) -3.5398 1.79372 0.0179372 0.0193031
LQ 0.7205 0.01771 0.0001771 0.0001730
LPL 0.4389 0.29323 0.0029323 0.0023149
LPF 0.4269 0.10194 0.0010194 0.0010259
LPK -0.2180 0.34276 0.0034276 0.0037750
sigma2 0.1564 0.01906 0.0001906 0.0001705
この場合大差ないことが分かると思います.
* bayesm(Bayesian Inference for Marketing/Micro-econometrics) [#abbb0c92]
[[bayesmパッケージ中のオブジェクト一覧]]
*MCMCglmm: MCMC 一般化混合モデル [#gc0a7d64]
//MCMC Generalised Linear Mixed Models
*BUGS/WinBUGS [#xb8bd283]
BUGS はベイズ推定のためのパッケージソフトで、MCMC 法により事後分布の密度関数の計算を行います。
WinBUGS はその Windows 版です。
WinBUGS 自体は単体で使えますが、R から呼び出したほうが簡単です。
//谷村晋 2006年8月17日加筆
// UNIX/LINUX での BUGS の呼び出し方については、筆者が試していないので略([[OpenBUGS]]を参照)。
WinBUGSはwineを使えばLinux上でも動作します。wine経由のWinBUGSもRから呼び出すことができます。
**インストール [#p81a1dbf]
WinBUGS は以下からダウンロードできます。WinBUGS の機能をすべて使うには、登録が必要です(無償)。
[[BUGS Project:http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/contents.shtml]]のページ
インストールが終わって、BUGS のコードも借りてくれば、R さえ使えれば WinBUGS について何も知らなくても使えます。
BUGSのコードは、例えば、
Lncaster, Tony. An Intoroduction to Modern Bayesian Econometrics. Blackwell, 2004.
にあります。
//谷村晋 2006年8月17日加筆
Linuxへのインストールは、Windowsと同様です。wineが正しく設定してあればWinBUGSをダウンロードするときにそのままwineでWinBUGSのインストーラを起動することができます。ダウンロード時にディスクに保存せずにそのままインストールした方が楽でしょう。
Rの側のパッケージは"R2WinBUGS"または"rbugs"です。"rbugs"はLinux上での利用を想定されたものでLinBUGS(デフォルト)/OpenBUGS/wine経由のWinBUGSをサポートしています。Linuxでは"rbugs"以外にWinBUGSと連携するためのパッケージがありませんでしたが、今のR2WinBUGSはwine経由のWinBUGSにも対応しているので、Linux上でも"R2WinBUGS"を使うことができます。ただし、[[1つバグ:http://finzi.psych.upenn.edu/R/Rhelp02a/archive/75440.html]]があり、wine経由のWinBUGSをR2WinBUGSから操作するには、bugs()の前に
WINEPATH <- "/usr/bin/winepath"
というおまじないが必要です。このバグは現在(2006年8月17日)も修正されていません。
"R2WinBUGS"を使う前に、
library(R2WinBUGS)
help(package="R2WinBUGS")
ここから、例をConsoleにコピーすれば、すぐにWinBUGSが走ります。
**線形回帰モデルの例 (数値例は仮設) [#m8529f09]
+model.fileの作成。BUGSのコードです。
"model.txt"などの名前でRのワーキング・ディレクトリに保存します。
model{
for(i in 1:n){y[i]~dnorm(mu[i],tau)
mu[i] <-alpha + beta1*x[i,1]+beta2*x[i,2]
}
alpha ~dnorm(0,0.0001)
beta1 ~dnorm(0,0.0001)
beta2 ~dnorm(0,0.0001)
tau ~dgamma(0.001, 0.001)
}
+データの作成(ノーテンションはmodel.fileにあわせます)
y <- c(1,3,3,3,5)
n <- NROW(y)
x1 <- c(1,2,3,5,5)
x2 <- c(2,3,1,5,2)
x <- matrix(c(x1,x2),ncol=2,nrow=5)
data <- list ("n", "y", "x")
+初期値の決定・結果を保存したいパラメータを指定
in1 <- list(alpha=0, beta1=0, beta2=0, tau=1)
in2 <- list(alpha=1, beta1=1, beta2=1, tau=1)
in3 <- list(alpha=2, beta1=2, beta2=2, tau=1)
inits <- list(in1,in2,in3)
parameters <- c("alpha", "beta1", "beta2", "tau")
+WinBUGSを走らせます。debug=TRUEにすれば、デバッグできます。
result.sim <- bugs(data, inits, parameters, model.file="model.txt",
n.chains = 3, n.iter = 1000, debug=FALSE,
bugs.directory = "c:/Program Files/WinBUGS14/",
working.directory = NULL)
+結果を見ます。例えば、
print(result.sim,digits=3)
result.sim$sims.list$beta1
--ちなみに、olsだと
result2.sim <- lm(y~x1+x2)
summary(result2.sim)
--パッケージ"MCMCpack"を使うと
line <- list ("y", "x")
result3.sim <- MCMCregress(y~x, data = parent.frame(), burnin = 1000, mcmc = 10000)
+本来は、このあとlibrary coda をつかってマルコフ連鎖の収束判定をするべきです。
*エラーとの戦い [#cb9c88fb]
//2213 加筆です。(2009/02/05)
-Permission denied 加筆者はVistaのUAC(ユーザーアカウント制御)解除でクリア(自己責任でお願いします。)
-educational version 対応パッチ?を[[WinBugsのページ:http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/register.shtml]]からおとしてください。
*パッケージソフトで対応できない場合 [#rf61bc64]
R の関数だけをつかって MCMC 法を実行するのは速度的に厳しいため、全体を C/C++ で書き、それを R から呼ぶという方法を推奨します。
詳しくは、[[Rから他言語利用]]を参照のこと。
*ベイズネットワーク [#kfed0448]
*[[Stan:http://mc-stan.org/]] [#x38e2b29]
-[[RStan:http://mc-stan.org/r-quickstart.html]]|
--[[RStan: Fast, multilevel Bayesian modeling in R:http://blog.revolutionanalytics.com/2012/08/rstan-fast-multilevel-bayesian-modeling-in-r.html]]
--[[Stan for Bayesian Analysis:http://www.r-bloggers.com/stan-for-bayesian-analysis/]]
--R: RStanをためす
---[[1:http://ito-hi.blog.so-net.ne.jp/2012-09-01]],[[2:http://ito-hi.blog.so-net.ne.jp/2012-09-02]],[[3:http://ito-hi.blog.so-net.ne.jp/2012-09-17]]
--[[RStudioでStanがi386のライブラリをよみにいくとき:http://ito-hi.blog.so-net.ne.jp/2012-11-02]]
*参考書 [#c5bca139]
+Koop, Gary. Bayesian Econometrics. Wiley, 2003.
+Lncaster, Tony. An Intoroduction to Modern Bayesian Econometrics. Blackwell, 2004.
+中妻照雄『ファイナンスのためのMCMC法によるベイズ分析』三菱経済研究所, 2003年
+[[和合肇編著『ベイズ計量経済分析』東洋経済新報社, 2005.:http://www.amazon.co.jp/%E3%83%99%E3%82%A4%E3%82%BA%E8%A8%88%E9%87%8F%E7%B5%8C%E6%B8%88%E5%88%86%E6%9E%90%E2%80%95%E3%83%9E%E3%83%AB%E3%82%B3%E3%83%95%E9%80%A3%E9%8E%96%E3%83%A2%E3%83%B3%E3%83%86%E3%82%AB%E3%83%AB%E3%83%AD%E6%B3%95%E3%81%A8%E3%81%9D%E3%81%AE%E5%BF%9C%E7%94%A8-%E5%92%8C%E5%90%88-%E8%82%87/dp/4492313397]]
+Williams, David. Weighing the Odds. Cambridge University Press, 2001.
+[[経済・経営のための統計学(2005, 有斐閣):http://www.amazon.co.jp/%E7%B5%8C%E6%B8%88%E3%83%BB%E7%B5%8C%E5%96%B6%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AE%E7%B5%B1%E8%A8%88%E5%AD%A6-%E6%9C%89%E6%96%90%E9%96%A3%E3%82%A2%E3%83%AB%E3%83%9E-%E7%89%A7-%E5%8E%9A%E5%BF%97/dp/4641122458]]
9章 ベイズ統計
+[[Bayesian Statistics and Marketing:http://gsbwww.uchicago.edu/fac/peter.rossi/research/bsm.html]] Greg Allenby, Rob McCulloch, Peter Rossi, 2005, John Wiley & Sons~
この本のDraftとRのコード。
+[[Bayesian Data Analysis, 2nd Ed.:http://www.crcpress.com/shopping_cart/products/product_detail.asp?sku=C388X&parent_id=&pc=]] Andrew Gelman, John B. Carlin, Hal S. Stern, Donald B. Rubin, 2003, Crc Pr I Llc.~
Appendix C が "Example of computation in R and Bugs"という題になっており,
そこにRのコードが書いてあります。
--[[Andrew Gelmanのサイト:http://www.stat.columbia.edu/~gelman/book/]]にPDFファイルがあります(『Appendix C from the second edition of Bayesian Data Analysis』).
+[[A Practical Approach to Computational Bayesian Statistics:http://www.amazon.co.jp/Bayesian-Core-Practical-Computational-Statistics/dp/0387389792/ref=sr_11_1/503-7622661-8431115]] Jean-Michel Marin, Christian P. Robert, 2007, Springer.
+[[Data Analysis Using Regression and Multilevel/Hierarchical Models:http://www.stat.columbia.edu/~gelman/arm/]] Andrew Gelman, Jennifer Hill, 2007, Cambridge University Press、このサイトにプログラム、データ、正誤表あり
+R News, Volume 5/2, November 2005
BMA の紹介
+[[R News, volume 6/1, issue 1:http://cran.r-project.org/doc/Rnews/Rnews_2006-1.pdf]]
ベイズ関連パッケージの特集
+[[Bayesian Computation with R (Use R) :http://www.amazon.co.jp/Bayesian-Computation-R-Use/dp/0387713840/ref=pd_ys_ir_all_7/249-8611663-8418753]] Albert, J., 2007,Springer. 著者作成の LearnBayes パッケージ(CRAN にあり)を利用
+[[Data Analysis Using Regression and Multilevel/Hierarchical Models:http://www.amazon.co.jp/dp/0521867061/ref=s9_asin_title_2/249-8611663-8418753?pf_rd_m=AN1VRQENFRJN5&pf_rd_s=center-2&pf_rd_r=1V4B4717C24TWQYJ2Q54&pf_rd_t=101&pf_rd_p=61605506&pf_rd_i=489986]] Andrew Gelman and Jennifer Hill, 2006, Cambridge Univ Pr. マルチレベル階層分析のハンドブック。R と WinBUGS を利用。
+[[『マルコフ連鎖モンテカルロ法』:http://www.asakura.co.jp/books/isbn/978-4-254-12697-6/]] 豊田秀樹 編著, 2007, 朝倉書店.
+[[Bayesian Disease Mapping: Hierarchical Modeling in Spatial Epidemiology:http://www.crcpress.com/shopping_cart/products/product_detail.asp?sku=C8407&isbn=9781584888406&parent_id=500&pc=]]
+[[Hierarchical Modeling and Analysis for Spatial Data:http://www.crcpress.com/shopping_cart/products/product_detail.asp?sku=C410X&isbn=9781584884101&parent_id=500&pc=]] GeoR
+[[Hierarchical Modeling and Analysis for Spatial Data(Monographs on Statistics & Applied Probability) 2nd Ed. :http://www.amazon.co.uk/dp/1439819173?tag=spatialanalys-21&camp=2202&creative=7754&linkCode=op1&creativeASIN=1439819173&adid=0GVNXGXR5H02PEFHNNQP&]], Sudipto Banerje, S., Gelfand, A. E., Carlin, B. P., 2011,CRC, pp. 608.
+『Rによるマーケティング・シミュレーション』
+ [[BAYESIAN METHODS: A Social and Behavioral Sciences Approach, Second Edition:http://www.crcpress.com/shopping_cart/products/product_detail.asp?sku=C5629&isbn=9781584885627&parent_id=501&pc=]] サポートパッケージ:BaM @ CRAN
+古谷知之著[[『ベイズ統計データ分析 ―R & WinBUGS― (統計ライブラリー)』:http://www.asakura.co.jp/books/isbn/978-4-254-12698-3/]],朝倉書店,2008.
+Bolstad, W.M. (2007):"Introduction to Bayesian Statistics", John Wiley & Sons ISBN 0-471-27020-2
+姜 興起 著(2010):[[『ベイズ統計データ解析』:http://www.kyoritsu-pub.co.jp/series/arudemanabu.html#3]]、共立出版
+安道知寛 著[[『ベイズ統計モデリング』:http://www.asakura.co.jp/books/isbn/978-4-254-12793-5/]],朝倉書店
+照井伸彦 著 :[[『Rによるベイズ統計分析』:http://www.asakura.co.jp/books/isbn/978-4-254-12812-3/]],朝倉書店
+[[Introduction to Probability Simulation and Gibbs Sampling with R:http://www.springer.com/statistics/statistical+theory+and+methods/book/978-0-387-40273-4]] Eric A., Trumbo, Bruce E.,2010, Springer.
+[[Bayesian Ideas and Data Analysis: An Introduction for Scientists and Statisticians:http://www.crcpress.com/product/isbn/9781439803547]], Christensen R., Johnson W. O., Branscum A. J., Hanson T. E., 2010, Chapman & Hall/CRC.
+[[Bayesian Model Selection and Statistical Modeling:http://www.crcpress.com/product/isbn/9781439836149]], Ando T., 2010, CRC press. [[サポートページ:http://labs.kbs.keio.ac.jp/andotomohiro/Bayesianbook.htm]]
+J.アルバート (著) 、石田 基広・石田 和枝 (共訳) (2010):[[Rで学ぶベイズ統計学入門:http://www.amazon.co.jp/dp/4431102388/]] シュプリンガー・ジャパン
+古谷知之著[[『Rによる空間データの統計分析』:http://www.asakura.co.jp/books/isbn/978-4-254-12815-4/]],朝倉書店,2011.
+Kruschke, J.:[[Doing Bayesian Data Analysis: A Tutorial Introduction with R and BUGS:http://www.amazon.co.jp/Doing-Bayesian-Data-Analysis-Introduction/dp/0123814855]], Academic Press, 2010
+Efron, Bradley:[[Large-Scale Inference: Empirical Bayes Methods for Estimation, Testing, and Prediction (Institute of Mathematical Statistics Monographs) :http://www.amazon.co.jp/Large-Scale-Inference-Estimation-Prediction-Mathematical/dp/0521192498]], Cambridge University Press,2010.
+久保 拓弥著:[[データ解析のための統計モデリング入門 ―― 一般化線形モデル・階層ベイズモデル・MCMC ――:http://www.iwanami.co.jp/cgi-bin/isearch?isbn=ISBN978-4-00-006973-1]], 岩波書店,2012.
+Yau, C.:[[R Tutorial with Bayesian Statistics Using OpenBUGS:http://www.amazon.com/Tutorial-Bayesian-Statistics-OpenBUGS-ebook/dp/B006ZP4SKW/ref=sr_1_1?ie=UTF8&qid=1350884313&sr=8-1&keywords=R+Tutorial+with+Bayesian+Statistics+Using+OpenBUGS]], Amazon Digital Services, Inc., 2012.
+[[Bayesian Inference Using OpenBUGS:http://www.r-tutor.com/bayesian-statistics/openbugs]]
+[[The BUGS Book: A Practical Introduction to Bayesian Analysis:http://www.crcpress.com/product/isbn/9781584888499]],Chapman & Hall/CRC , 2012. [[サポートサイト:http://www.mrc-bsu.cam.ac.uk/bugs/thebugsbook/]]
+G.ペトリス ・S.ペトローネ ・P.カンパニョーリ 著/和合肇 監訳/萩原淳一郎 訳:[[Rによるベイジアン動的線型モデル:http://www.asakura.co.jp/books/isbn/978-4-254-12796-6/]],朝倉書店,2014.
*関連サイト [#r01ed898]
-[[ベイズ統計学のページ:http://web.mita.keio.ac.jp/~ds064410/wiki.cgi?page=%A5%D9%A5%A4%A5%BA%C5%FD%B7%D7%B3%D8%A4%CE%A5%DA%A1%BC%A5%B8]]
-[[Bayes:http://www.rhasumi.net/wiki/wiki.cgi?page=Bayes]]
-[[生態学のデータ解析 - ベイズ統計 & MCMC:http://hosho.ees.hokudai.ac.jp/~kubo/ce/BayesianMcmc.html]]
-空間生存分析
-空間パネル分析
-[[Bayesian Model Averaging (BMA) with uncertain Spatial Effects:http://www.r-bloggers.com/bayesian-model-averaging-bma-with-uncertain-spatial-effects/]] spdep + BMA
-[[OBANSoft: integrated software for Bayesian statistics and high performance computing with R:http://www.warwick.ac.uk/statsdept/user-2011/TalkSlides/Contributed/16Aug_1115_FocusI_3-HighPerfComp_4-Quesada.pdf]]
-[[General Bayesian estimation using MHadaptive:http://www.r-bloggers.com/general-bayesian-estimation-using-mhadaptive/]]
-[[maps2winbugsplugin:http://code.google.com/p/maps2winbugsplugin/]] maps2WinBUGS plugin for Quantum GIS
-[[線形混合モデル/階層線形モデル/マルチレベル分析について:http://mizumot.com/lablog/?p=179]]
-[[Let's Do Some Hierarchical Bayes Choice Modeling in R!:http://joelcadwell.blogspot.jp/2013/03/lets-do-some-hierarchical-bayes-choice.html]]
-[[BayesComp:http://bayescomp.wikidot.com]]
--[[BayesComp homepage:http://xianblog.wordpress.com/2013/04/15/bayescomp-homepage/]]
-[[Bayesian computational tools:http://xianblog.wordpress.com/2013/06/18/bayesian-computational-tools-2/]]
-[[R and Bayesian Statistics:http://blog.revolutionanalytics.com/2013/11/r-and-bayesian-statistics.html]]
-[[Easy Laplace Approximation of Bayesian Models in R:http://www.sumsar.net/blog/2013/06/three-ways-to-run-bayesian-models-in-r/]]
*コメント [#sf91b9f2]
- RというよりWinbugs本かもしれないですが、[[カエル本の訳本:http://www.kyoritsu-pub.co.jp/kinkan/shosai/kin05678-7.html]]がでるのですね。 -- [[そう]] &new{2009-01-26 (月) 19:56:58};
#comment
ページ名: