Rでベイズ統計学
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
SIZE(25){COLOR(red){Rでベイズ統計学}}
//written by 蓮見亮 10/10/2005
筆者は計量経済学が専攻なので、それ以外の分野の方のフォロ...
#contents
~
*ベイズ統計学とは? [#zb04fab6]
統計的推論にベイズの定理を使う方法をいいます。
方法に一貫性があること、柔軟なモデルに対応できること、一...
より詳しくは、[[松原先生のサイト:http://www.qmss.jp/appst...
*パッケージの一括インストール [#nf20f2fb]
詳しくは [[CRAN Task View]] (一般化モデルのあてはめ、特定...
install.packages("ctv")
library(ctv)
install.views("Bayesian")
で、必要なものはほぼすべて入ります。
個別のパッケージについては、
-[[CRAN Task View: Bayesian Inference:http://cran.r-proje...
を参照されたい。
**詳細 [#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 ...
-bayesm: Bayesian Inference for Marketing/Micro-econometr...
[[bayesmパッケージ(マーケティング/マイクロ計量経済学の...
-eco: R Package for Fitting Bayesian Models of Ecological...
-evdbayes: 極値理論のベイズ分析
-BMA: Bayesian Model Averaging
-MSBVAR: Bayesian Vector Autoregression Models, Impulse R...
-BACCO: Bundle of emulator, calibrator Bayesian analysis ...
-Zelig:[[Bayesian Multinomial Logistic Regression, Bayesi...
-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, Stanfo...
-bcp: Bayesian Change Point
--[[bcp(ベイジアン変化点)パッケージ中のオブジェクト一覧]]
-[[JAGS]]ギブス抽出法を用いたベイズ階層モデルの分析プログ...
-RJaCGH: CGH 配列解析のための Reversible Jump MCMC.
-MasterBayes: ML and MCMC Methods for Pedigree Reconstruc...
-BayHaz: R Functions for Bayesian Hazard Rate Estimation
-sbgcop: Semiparametric Bayesian Gaussian copula estimati...
-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 naiv...
-predmixcor: Classification rule based on Bayesian mixtur...
-geoR(地球統計用データ分析関数)パッケージ
ベイズ分析対応の関数がある
-ramps: RAMPS を
使ったベイズ地球統計モデリング(Bayesian Geostatistical Mo...
-BAYSTAR: On Bayesian analysis of Threshold autoregressiv...
-bayescount: Bayesian analysis of count distributions wit...
-cobs: COBS -- 拘束条件付きの B-スプライン (Sparse matri...
-pscl: Political Science Computational Laboratory, Stanfo...
--Bayesian analysis of item-response theory (IRT) models
-BPHO: 工事の相互作用についてのベイズ予測
//Bayesian Prediction with High-order Interactions
-siar: R での安定アイソトープ分析(Stable Isotope Analysis...
--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 fro...
-ensembleBMA: アンサンブルおよびベイズモデル平均化を使っ...
[[アンサンブル予測:http://www.jma.go.jp/jma/kishou/know/k...
-dlm: Bayesian and Likelihood Analysis of Dynamic Linear ...
-bayesGARCH: Bayesian Estimation of the GARCH(1,1) Model ...
-BaM: Functions and datasets for books by Jeff Gill
Books is "Bayesian Methods: A Social and Behavioral Scien...
-bark: ベイズ加法回帰カーネル Bayesian Additive Regresss...
-rv: Simulation-based random variable object class in R
-SimpleTable: Bayesian Inference and Sensitivity Analysis...
-glmmBUGS: WinBUGS をもちいた一般化線形混合モデル
-Bolstad: Bolstad の関数
-bayesclust: Tests/Searches for significant clusters in g...
-BAS: Bayesian Model Averaging using Bayesian Adaptive Sa...
-BayesX: R Utilities Accompanying the Software Package Ba...
-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 Equil...
-emulator: Bayesian emulation of computer programs
-WMCapacity: GUI implementing Bayesian working memory mod...
-BayesQTLBIC: Bayesian multi-locus QTL analysis based on ...
-Bolstad2: Bolstad functions
-arm: 回帰及びマルチレベル/階層モデルを使ったデータ分析
// Data Analysis Using Regression and Multilevel/Hierarch...
-CORElearn: CORElearn - classification, regression, featu...
-Bergm: Bayesian inference for exponential random graph m...
-cudaBayesreg: fMRI データ分析用マルチレベルモデルの CUDA...
//CUDA Parallel Implementation of a Bayesian Multilevel M...
-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...
-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 Gaus...
-Bchron: Bayesian chronologies via compound Poisson-Gamma...
-abc: Functions to perform Approximate Bayesian Computati...
-bayesLife: Bayesian Projection of Life Expectancy
-bayesTFR: Bayesian Fertility Projection
-varSelectIP: Objective Bayes Model Selection
-HPbayes: Heligman Pollard mortality model parameter esti...
-LaplacesDemon: Laplace's Demon: Software for Bayesian In...
-BAMD: Bayesian Association Model for Genomic Data with M...
-MISA: Bayesian Model Search and Multilevel Inference for...
-monomvn: Estimation for multivariate normal and Student-...
-[[casper:https://r-forge.r-project.org/projects/casper/]...
-BCBCSF: Bias-corrected Bayesian Classification with Sele...
-rriskBayes: Predefined Bayes models fitted with Markov c...
-JMbayes: Joint Modeling of Longitudinal and Time-to-Even...
-sdnet: Soft Discretization-based Bayesian Network Infere...
-[[bscr: Bayesian parametric and semi-parametric analyses...
-[[spatialprobit: Spatial Probit Models:http://cran.rstud...
-[[gsbDesign: Group Sequential Bayes Design:http://cran.m...
-[[PReMiuM: Dirichlet Process Bayesian Clustering, Profil...
-[[Bayesian Statistics@R-Forge:https://r-forge.r-project....
--[[BayesSDEmacroevolution:http://bayessdeevol.r-forge.r-...
-[[tsbugs: Create time series BUGS models:http://cran.r-p...
--[[The tsbugs package for R:http://gjabel.wordpress.com/...
-[[CRAN Task View: Bayesian Inference:http://cran.r-proje...
--モデルのあてはめ(Bayesian packages for general model fi...
まずは 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,...
Elec<-read.table("http://www.rhasumi.net/data/econometri...
LTC<-log(Elec[,1]); LQ <- log(Elec[,2]); LPL <- log(Elec...
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...
#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 variab...
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-econometr...
[[bayesmパッケージ中のオブジェクト一覧]]
*MCMCglmm: MCMC 一般化混合モデル [#gc0a7d64]
//MCMC Generalised Linear Mixed Models
*BUGS/WinBUGS [#xb8bd283]
BUGS はベイズ推定のためのパッケージソフトで、MCMC 法によ...
WinBUGS はその Windows 版です。
WinBUGS 自体は単体で使えますが、R から呼び出したほうが簡...
//谷村晋 2006年8月17日加筆
// UNIX/LINUX での BUGS の呼び出し方については、筆者が試...
WinBUGSはwineを使えばLinux上でも動作します。wine経由のWin...
**インストール [#p81a1dbf]
WinBUGS は以下からダウンロードできます。WinBUGS の機能を...
[[BUGS Project:http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/...
インストールが終わって、BUGS のコードも借りてくれば、R さ...
BUGSのコードは、例えば、
Lncaster, Tony. An Intoroduction to Modern Bayesian Econo...
にあります。
//谷村晋 2006年8月17日加筆
Linuxへのインストールは、Windowsと同様です。wineが正しく...
Rの側のパッケージは"R2WinBUGS"または"rbugs"です。"rbugs"...
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="...
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(), b...
+本来は、このあとlibrary coda をつかってマルコフ連鎖の収...
*エラーとの戦い [#cb9c88fb]
//2213 加筆です。(2009/02/05)
-Permission denied 加筆者はVistaのUAC(ユーザーアカ...
-educational version 対応パッチ?を[[WinBugsのページ...
*パッケージソフトで対応できない場合 [#rf61bc64]
R の関数だけをつかって MCMC 法を実行するのは速度的に厳し...
詳しくは、[[Rから他言語利用]]を参照のこと。
*ベイズネットワーク [#kfed0448]
*[[Stan:http://mc-stan.org/]] [#x38e2b29]
-[[RStan:http://mc-stan.org/r-quickstart.html]]|
--[[RStan: Fast, multilevel Bayesian modeling in R:http:/...
--[[Stan for Bayesian Analysis:http://www.r-bloggers.com/...
--R: RStanをためす
---[[1:http://ito-hi.blog.so-net.ne.jp/2012-09-01]],[[2:h...
--[[RStudioでStanがi386のライブラリをよみにいくとき:http:...
*参考書 [#c5bca139]
+Koop, Gary. Bayesian Econometrics. Wiley, 2003.
+Lncaster, Tony. An Intoroduction to Modern Bayesian Econ...
+中妻照雄『ファイナンスのためのMCMC法によるベイズ分析』三...
+[[和合肇編著『ベイズ計量経済分析』東洋経済新報社, 2005.:...
+Williams, David. Weighing the Odds. Cambridge University...
+[[経済・経営のための統計学(2005, 有斐閣):http://www.amaz...
9章 ベイズ統計
+[[Bayesian Statistics and Marketing:http://gsbwww.uchica...
この本のDraftとRのコード。
+[[Bayesian Data Analysis, 2nd Ed.:http://www.crcpress.co...
Appendix C が "Example of computation in R and Bugs"とい...
そこにRのコードが書いてあります。
--[[Andrew Gelmanのサイト:http://www.stat.columbia.edu/~g...
+[[A Practical Approach to Computational Bayesian Statist...
+[[Data Analysis Using Regression and Multilevel/Hierarch...
+R News, Volume 5/2, November 2005
BMA の紹介
+[[R News, volume 6/1, issue 1:http://cran.r-project.org/...
ベイズ関連パッケージの特集
+[[Bayesian Computation with R (Use R) :http://www.amazon...
+[[Data Analysis Using Regression and Multilevel/Hierarch...
+[[『マルコフ連鎖モンテカルロ法』:http://www.asakura.co.j...
+[[Bayesian Disease Mapping: Hierarchical Modeling in Spa...
+[[Hierarchical Modeling and Analysis for Spatial Data:ht...
+[[Hierarchical Modeling and Analysis for Spatial Data(Mo...
+『Rによるマーケティング・シミュレーション』
+ [[BAYESIAN METHODS: A Social and Behavioral Sciences Ap...
+古谷知之著[[『ベイズ統計データ分析 ―R & WinBUGS― (統計...
+Bolstad, W.M. (2007):"Introduction to Bayesian Statistic...
+姜 興起 著(2010):[[『ベイズ統計データ解析』:http://www...
+安道知寛 著[[『ベイズ統計モデリング』:http://www.asakura...
+照井伸彦 著 :[[『Rによるベイズ統計分析』:http://www.asak...
+[[Introduction to Probability Simulation and Gibbs Sampl...
+[[Bayesian Ideas and Data Analysis: An Introduction for ...
+[[Bayesian Model Selection and Statistical Modeling:http...
+J.アルバート (著) 、石田 基広・石田 和枝 (共訳) (2010):[...
+古谷知之著[[『Rによる空間データの統計分析』:http://www.a...
+Kruschke, J.:[[Doing Bayesian Data Analysis: A Tutorial ...
+Efron, Bradley:[[Large-Scale Inference: Empirical Bayes ...
+久保 拓弥著:[[データ解析のための統計モデリング入門 ―― ...
+Yau, C.:[[R Tutorial with Bayesian Statistics Using Open...
+[[Bayesian Inference Using OpenBUGS:http://www.r-tutor.c...
+[[The BUGS Book: A Practical Introduction to Bayesian An...
+G.ペトリス ・S.ペトローネ ・P.カンパニョーリ 著/和合肇 ...
*関連サイト [#r01ed898]
-[[ベイズ統計学のページ:http://web.mita.keio.ac.jp/~ds064...
-[[Bayes:http://www.rhasumi.net/wiki/wiki.cgi?page=Bayes]]
-[[生態学のデータ解析 - ベイズ統計 & MCMC:http://hosho.ee...
-空間生存分析
-空間パネル分析
-[[Bayesian Model Averaging (BMA) with uncertain Spatial ...
-[[OBANSoft: integrated software for Bayesian statistics ...
-[[General Bayesian estimation using MHadaptive:http://ww...
-[[maps2winbugsplugin:http://code.google.com/p/maps2winbu...
-[[線形混合モデル/階層線形モデル/マルチレベル分析について...
-[[Let's Do Some Hierarchical Bayes Choice Modeling in R!...
-[[BayesComp:http://bayescomp.wikidot.com]]
--[[BayesComp homepage:http://xianblog.wordpress.com/2013...
-[[Bayesian computational tools:http://xianblog.wordpress...
-[[R and Bayesian Statistics:http://blog.revolutionanalyt...
-[[Easy Laplace Approximation of Bayesian Models in R:htt...
*コメント [#sf91b9f2]
- RというよりWinbugs本かもしれないですが、[[カエル本の訳...
#comment
終了行:
SIZE(25){COLOR(red){Rでベイズ統計学}}
//written by 蓮見亮 10/10/2005
筆者は計量経済学が専攻なので、それ以外の分野の方のフォロ...
#contents
~
*ベイズ統計学とは? [#zb04fab6]
統計的推論にベイズの定理を使う方法をいいます。
方法に一貫性があること、柔軟なモデルに対応できること、一...
より詳しくは、[[松原先生のサイト:http://www.qmss.jp/appst...
*パッケージの一括インストール [#nf20f2fb]
詳しくは [[CRAN Task View]] (一般化モデルのあてはめ、特定...
install.packages("ctv")
library(ctv)
install.views("Bayesian")
で、必要なものはほぼすべて入ります。
個別のパッケージについては、
-[[CRAN Task View: Bayesian Inference:http://cran.r-proje...
を参照されたい。
**詳細 [#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 ...
-bayesm: Bayesian Inference for Marketing/Micro-econometr...
[[bayesmパッケージ(マーケティング/マイクロ計量経済学の...
-eco: R Package for Fitting Bayesian Models of Ecological...
-evdbayes: 極値理論のベイズ分析
-BMA: Bayesian Model Averaging
-MSBVAR: Bayesian Vector Autoregression Models, Impulse R...
-BACCO: Bundle of emulator, calibrator Bayesian analysis ...
-Zelig:[[Bayesian Multinomial Logistic Regression, Bayesi...
-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, Stanfo...
-bcp: Bayesian Change Point
--[[bcp(ベイジアン変化点)パッケージ中のオブジェクト一覧]]
-[[JAGS]]ギブス抽出法を用いたベイズ階層モデルの分析プログ...
-RJaCGH: CGH 配列解析のための Reversible Jump MCMC.
-MasterBayes: ML and MCMC Methods for Pedigree Reconstruc...
-BayHaz: R Functions for Bayesian Hazard Rate Estimation
-sbgcop: Semiparametric Bayesian Gaussian copula estimati...
-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 naiv...
-predmixcor: Classification rule based on Bayesian mixtur...
-geoR(地球統計用データ分析関数)パッケージ
ベイズ分析対応の関数がある
-ramps: RAMPS を
使ったベイズ地球統計モデリング(Bayesian Geostatistical Mo...
-BAYSTAR: On Bayesian analysis of Threshold autoregressiv...
-bayescount: Bayesian analysis of count distributions wit...
-cobs: COBS -- 拘束条件付きの B-スプライン (Sparse matri...
-pscl: Political Science Computational Laboratory, Stanfo...
--Bayesian analysis of item-response theory (IRT) models
-BPHO: 工事の相互作用についてのベイズ予測
//Bayesian Prediction with High-order Interactions
-siar: R での安定アイソトープ分析(Stable Isotope Analysis...
--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 fro...
-ensembleBMA: アンサンブルおよびベイズモデル平均化を使っ...
[[アンサンブル予測:http://www.jma.go.jp/jma/kishou/know/k...
-dlm: Bayesian and Likelihood Analysis of Dynamic Linear ...
-bayesGARCH: Bayesian Estimation of the GARCH(1,1) Model ...
-BaM: Functions and datasets for books by Jeff Gill
Books is "Bayesian Methods: A Social and Behavioral Scien...
-bark: ベイズ加法回帰カーネル Bayesian Additive Regresss...
-rv: Simulation-based random variable object class in R
-SimpleTable: Bayesian Inference and Sensitivity Analysis...
-glmmBUGS: WinBUGS をもちいた一般化線形混合モデル
-Bolstad: Bolstad の関数
-bayesclust: Tests/Searches for significant clusters in g...
-BAS: Bayesian Model Averaging using Bayesian Adaptive Sa...
-BayesX: R Utilities Accompanying the Software Package Ba...
-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 Equil...
-emulator: Bayesian emulation of computer programs
-WMCapacity: GUI implementing Bayesian working memory mod...
-BayesQTLBIC: Bayesian multi-locus QTL analysis based on ...
-Bolstad2: Bolstad functions
-arm: 回帰及びマルチレベル/階層モデルを使ったデータ分析
// Data Analysis Using Regression and Multilevel/Hierarch...
-CORElearn: CORElearn - classification, regression, featu...
-Bergm: Bayesian inference for exponential random graph m...
-cudaBayesreg: fMRI データ分析用マルチレベルモデルの CUDA...
//CUDA Parallel Implementation of a Bayesian Multilevel M...
-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...
-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 Gaus...
-Bchron: Bayesian chronologies via compound Poisson-Gamma...
-abc: Functions to perform Approximate Bayesian Computati...
-bayesLife: Bayesian Projection of Life Expectancy
-bayesTFR: Bayesian Fertility Projection
-varSelectIP: Objective Bayes Model Selection
-HPbayes: Heligman Pollard mortality model parameter esti...
-LaplacesDemon: Laplace's Demon: Software for Bayesian In...
-BAMD: Bayesian Association Model for Genomic Data with M...
-MISA: Bayesian Model Search and Multilevel Inference for...
-monomvn: Estimation for multivariate normal and Student-...
-[[casper:https://r-forge.r-project.org/projects/casper/]...
-BCBCSF: Bias-corrected Bayesian Classification with Sele...
-rriskBayes: Predefined Bayes models fitted with Markov c...
-JMbayes: Joint Modeling of Longitudinal and Time-to-Even...
-sdnet: Soft Discretization-based Bayesian Network Infere...
-[[bscr: Bayesian parametric and semi-parametric analyses...
-[[spatialprobit: Spatial Probit Models:http://cran.rstud...
-[[gsbDesign: Group Sequential Bayes Design:http://cran.m...
-[[PReMiuM: Dirichlet Process Bayesian Clustering, Profil...
-[[Bayesian Statistics@R-Forge:https://r-forge.r-project....
--[[BayesSDEmacroevolution:http://bayessdeevol.r-forge.r-...
-[[tsbugs: Create time series BUGS models:http://cran.r-p...
--[[The tsbugs package for R:http://gjabel.wordpress.com/...
-[[CRAN Task View: Bayesian Inference:http://cran.r-proje...
--モデルのあてはめ(Bayesian packages for general model fi...
まずは 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,...
Elec<-read.table("http://www.rhasumi.net/data/econometri...
LTC<-log(Elec[,1]); LQ <- log(Elec[,2]); LPL <- log(Elec...
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...
#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 variab...
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-econometr...
[[bayesmパッケージ中のオブジェクト一覧]]
*MCMCglmm: MCMC 一般化混合モデル [#gc0a7d64]
//MCMC Generalised Linear Mixed Models
*BUGS/WinBUGS [#xb8bd283]
BUGS はベイズ推定のためのパッケージソフトで、MCMC 法によ...
WinBUGS はその Windows 版です。
WinBUGS 自体は単体で使えますが、R から呼び出したほうが簡...
//谷村晋 2006年8月17日加筆
// UNIX/LINUX での BUGS の呼び出し方については、筆者が試...
WinBUGSはwineを使えばLinux上でも動作します。wine経由のWin...
**インストール [#p81a1dbf]
WinBUGS は以下からダウンロードできます。WinBUGS の機能を...
[[BUGS Project:http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/...
インストールが終わって、BUGS のコードも借りてくれば、R さ...
BUGSのコードは、例えば、
Lncaster, Tony. An Intoroduction to Modern Bayesian Econo...
にあります。
//谷村晋 2006年8月17日加筆
Linuxへのインストールは、Windowsと同様です。wineが正しく...
Rの側のパッケージは"R2WinBUGS"または"rbugs"です。"rbugs"...
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="...
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(), b...
+本来は、このあとlibrary coda をつかってマルコフ連鎖の収...
*エラーとの戦い [#cb9c88fb]
//2213 加筆です。(2009/02/05)
-Permission denied 加筆者はVistaのUAC(ユーザーアカ...
-educational version 対応パッチ?を[[WinBugsのページ...
*パッケージソフトで対応できない場合 [#rf61bc64]
R の関数だけをつかって MCMC 法を実行するのは速度的に厳し...
詳しくは、[[Rから他言語利用]]を参照のこと。
*ベイズネットワーク [#kfed0448]
*[[Stan:http://mc-stan.org/]] [#x38e2b29]
-[[RStan:http://mc-stan.org/r-quickstart.html]]|
--[[RStan: Fast, multilevel Bayesian modeling in R:http:/...
--[[Stan for Bayesian Analysis:http://www.r-bloggers.com/...
--R: RStanをためす
---[[1:http://ito-hi.blog.so-net.ne.jp/2012-09-01]],[[2:h...
--[[RStudioでStanがi386のライブラリをよみにいくとき:http:...
*参考書 [#c5bca139]
+Koop, Gary. Bayesian Econometrics. Wiley, 2003.
+Lncaster, Tony. An Intoroduction to Modern Bayesian Econ...
+中妻照雄『ファイナンスのためのMCMC法によるベイズ分析』三...
+[[和合肇編著『ベイズ計量経済分析』東洋経済新報社, 2005.:...
+Williams, David. Weighing the Odds. Cambridge University...
+[[経済・経営のための統計学(2005, 有斐閣):http://www.amaz...
9章 ベイズ統計
+[[Bayesian Statistics and Marketing:http://gsbwww.uchica...
この本のDraftとRのコード。
+[[Bayesian Data Analysis, 2nd Ed.:http://www.crcpress.co...
Appendix C が "Example of computation in R and Bugs"とい...
そこにRのコードが書いてあります。
--[[Andrew Gelmanのサイト:http://www.stat.columbia.edu/~g...
+[[A Practical Approach to Computational Bayesian Statist...
+[[Data Analysis Using Regression and Multilevel/Hierarch...
+R News, Volume 5/2, November 2005
BMA の紹介
+[[R News, volume 6/1, issue 1:http://cran.r-project.org/...
ベイズ関連パッケージの特集
+[[Bayesian Computation with R (Use R) :http://www.amazon...
+[[Data Analysis Using Regression and Multilevel/Hierarch...
+[[『マルコフ連鎖モンテカルロ法』:http://www.asakura.co.j...
+[[Bayesian Disease Mapping: Hierarchical Modeling in Spa...
+[[Hierarchical Modeling and Analysis for Spatial Data:ht...
+[[Hierarchical Modeling and Analysis for Spatial Data(Mo...
+『Rによるマーケティング・シミュレーション』
+ [[BAYESIAN METHODS: A Social and Behavioral Sciences Ap...
+古谷知之著[[『ベイズ統計データ分析 ―R & WinBUGS― (統計...
+Bolstad, W.M. (2007):"Introduction to Bayesian Statistic...
+姜 興起 著(2010):[[『ベイズ統計データ解析』:http://www...
+安道知寛 著[[『ベイズ統計モデリング』:http://www.asakura...
+照井伸彦 著 :[[『Rによるベイズ統計分析』:http://www.asak...
+[[Introduction to Probability Simulation and Gibbs Sampl...
+[[Bayesian Ideas and Data Analysis: An Introduction for ...
+[[Bayesian Model Selection and Statistical Modeling:http...
+J.アルバート (著) 、石田 基広・石田 和枝 (共訳) (2010):[...
+古谷知之著[[『Rによる空間データの統計分析』:http://www.a...
+Kruschke, J.:[[Doing Bayesian Data Analysis: A Tutorial ...
+Efron, Bradley:[[Large-Scale Inference: Empirical Bayes ...
+久保 拓弥著:[[データ解析のための統計モデリング入門 ―― ...
+Yau, C.:[[R Tutorial with Bayesian Statistics Using Open...
+[[Bayesian Inference Using OpenBUGS:http://www.r-tutor.c...
+[[The BUGS Book: A Practical Introduction to Bayesian An...
+G.ペトリス ・S.ペトローネ ・P.カンパニョーリ 著/和合肇 ...
*関連サイト [#r01ed898]
-[[ベイズ統計学のページ:http://web.mita.keio.ac.jp/~ds064...
-[[Bayes:http://www.rhasumi.net/wiki/wiki.cgi?page=Bayes]]
-[[生態学のデータ解析 - ベイズ統計 & MCMC:http://hosho.ee...
-空間生存分析
-空間パネル分析
-[[Bayesian Model Averaging (BMA) with uncertain Spatial ...
-[[OBANSoft: integrated software for Bayesian statistics ...
-[[General Bayesian estimation using MHadaptive:http://ww...
-[[maps2winbugsplugin:http://code.google.com/p/maps2winbu...
-[[線形混合モデル/階層線形モデル/マルチレベル分析について...
-[[Let's Do Some Hierarchical Bayes Choice Modeling in R!...
-[[BayesComp:http://bayescomp.wikidot.com]]
--[[BayesComp homepage:http://xianblog.wordpress.com/2013...
-[[Bayesian computational tools:http://xianblog.wordpress...
-[[R and Bayesian Statistics:http://blog.revolutionanalyt...
-[[Easy Laplace Approximation of Bayesian Models in R:htt...
*コメント [#sf91b9f2]
- RというよりWinbugs本かもしれないですが、[[カエル本の訳...
#comment
ページ名: