SSブログ

R: CARBayesをためす [統計]

CARBayesパッケージをためしてみる。

CARBayes: An R Package for Bayesian Spatial Modeling with Conditional Autoregressive Priors

久保本11章のデータをつかう。

library(CARBayes)

load(url("http://hosho.ees.hokudai.ac.jp/~kubo/stat/iwanamibook/fig/spatial/Y.RData"))

n.site <- length(Y)
W <- matrix(0, n.site, n.site)
for (i in 1:(n.site - 1)) {
  W[i, (i + 1)] <- 1
  W[(i + 1), i] <- 1
}

fit <- poisson.iarCAR(Y ~ 1, W = W,
                      burnin = 500, n.sample = 3500, thin = 3)

print(fit)

plot(1:n.site, Y, type = "p", las = 1,
     ylim = c(0, 20), xlab = "site", ylab = "Y")
lines(1:n.site, fit$fitted.values[, "Mean"])

結果

> print(fit)

#################
#### Model fitted
#################
Likelihood model - Poisson (log link function) 
Random effects model - Intrinsic CAR
Regression equation - Y ~ 1

############
#### Results
############
Posterior quantiles and DIC

            Median   2.5%  97.5% n.sample % accept
(Intercept) 2.2694 2.1785 2.3596     1000     65.3
tau2        0.0514 0.0253 0.1047     1000    100.0

DIC =  264.4977       p.d =  17.25021 

Rplot.png


タグ:R
nice!(1)  コメント(0)  トラックバック(0) 
共通テーマ:日記・雑感

nice! 1

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

Facebook コメント

トラックバック 0