Created
March 23, 2014 11:07
-
-
Save chiral/9721704 to your computer and use it in GitHub Desktop.
simple x-y 2 dimension linear bayes fit for non informed prior .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model { | |
for (i in 1:N) { | |
y[i] ~ dnorm(mu[i],tau) | |
mu[i] <- alpha + beta*pow(gamma,x[i]) | |
} | |
alpha ~ dnorm(0, 1.0E-6) | |
beta ~ dnorm(0, 1.0E-6) | |
gamma ~ dunif(0.0, 1.0) | |
tau ~ dgamma(0.01,0.01) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(R2WinBUGS) | |
library(coda) | |
data <- list( | |
x=c(1.0,1.5,1.5,1.5,2.5,4.0,5.0,5.0,7.0,8.0, | |
8.5,9.0,9.5,9.5,10.0,12.0,12.0,13.0,13.0,14.5, | |
15.5,15.5,16.5,17.0,22.5,29.0,31.5), | |
y=c(1.80, | |
1.85,1.87,1.77,2.02,2.27,2.15,2.26,2.47,2.19, | |
2.26,2.40,2.39,2.41,2.50,2.32,2.32,2.43,2.47, | |
2.56,2.65,2.47,2.64,2.56,2.70,2.72,2.57), | |
N=27) | |
inits <- function() { list(alpha=1,beta=1,tau=1,gamma=0.9) } | |
parameters <- c("alpha","beta","tau","gamma") | |
result.sim <- bugs(data, inits, parameters, | |
model.file="R/test1.bugs", | |
n.chains = 4, n.iter = 1000, | |
debug=FALSE, | |
working.directory=getwd()) | |
result.sim$sims.list$beta1 | |
print(result.sim, digits=3) | |
plot(as.mcmc(result.sim$sims.matrix)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment