winbugs

Specify a discrete weibull distribution in JAGS or BUGS for R

强颜欢笑 提交于 2019-12-11 06:12:37
问题 I am fitting a weibull model to discrete values using JAGS in R. I have no problem fitting a weibull to continuous data, but I run in to trouble when I switch to discrete values. Here is some data, and code to fit a weibull model in JAGS: #draw data from a weibull distribution y <- rweibull(200, shape = 1, scale = 0.9) #y <- round(y) #load jags, specify a jags model. library(runjags) j.model =" model{ for (i in 1:N){ y[i] ~ dweib(shape[i], scale[i]) shape[i] <- b1 scale[i] <- b2 } #priors b1

Trying to create and loop through matrix of unbalanced data in R

早过忘川 提交于 2019-12-08 13:06:02
问题 I am trying to conduct an hierarchical bayesian analysis but am having a little trouble with R and WinBUGS code. I don't have balanced data and am struggling with the coding. I have temperature data collected daily with iButtons (temperature recording devices) in transects and am trying to generate a model that relates this to remote sensing data. Unfortunately, each transect has a different number of iButtons so creating a 3D matrix of button(i), in transect(j), repeatedly "sampled" on day(t

Passing variable to WinBugs model in R

人走茶凉 提交于 2019-12-07 19:09:31
问题 I am using the R2WinBugs package. I would like to pass two parameter that are calculated previously in the R script to the model function c0yy <- 0.1 syy <- 0.0001 #Model model <- function(c0yy,syy){ #Likelihood for(i in 1:n){ y[i] ~ dnorm(mu[i],cyy) } #Regression formula for(i in 1:n){ mu[i] <- alpha + gamma * x[i] } #Priors for the regression parameters alpha ~ dnorm(0,0.000001) gamma ~ dnorm(0,0.000001) #Priors for the precision parameter cyy ~ dnorm(c0yy,syy) #Monitored variables beta <-

Passing variable to WinBugs model in R

丶灬走出姿态 提交于 2019-12-06 12:16:44
I am using the R2WinBugs package. I would like to pass two parameter that are calculated previously in the R script to the model function c0yy <- 0.1 syy <- 0.0001 #Model model <- function(c0yy,syy){ #Likelihood for(i in 1:n){ y[i] ~ dnorm(mu[i],cyy) } #Regression formula for(i in 1:n){ mu[i] <- alpha + gamma * x[i] } #Priors for the regression parameters alpha ~ dnorm(0,0.000001) gamma ~ dnorm(0,0.000001) #Priors for the precision parameter cyy ~ dnorm(c0yy,syy) #Monitored variables beta <- gamma/(alpha-1) } filename <- file.path(tempdir(), "Olm.txt") write.model(model, filename) but I get

How can I convert an mcmc.list to a bugs object?

一曲冷凌霜 提交于 2019-12-05 15:17:22
问题 I am using the rjags R library. The function coda.samples produces an mcmc.list , for example (from example(coda.samples) ): library(rjags) data(LINE) LINE$recompile() LINE.out <- coda.samples(LINE, c("alpha","beta","sigma"), n.iter=1000) class(LINE.out) [1] "mcmc.list" However, I would like to use the plot.bugs function, which requires a bugs object as input. Is it possible to convert an object from an mcmc.list to a bugs object, so that plot.bugs(LINE.out) ? Note that there is a similar

How can I convert an mcmc.list to a bugs object?

心不动则不痛 提交于 2019-12-04 01:27:36
I am using the rjags R library. The function coda.samples produces an mcmc.list , for example (from example(coda.samples) ): library(rjags) data(LINE) LINE$recompile() LINE.out <- coda.samples(LINE, c("alpha","beta","sigma"), n.iter=1000) class(LINE.out) [1] "mcmc.list" However, I would like to use the plot.bugs function, which requires a bugs object as input. Is it possible to convert an object from an mcmc.list to a bugs object, so that plot.bugs(LINE.out) ? Note that there is a similar question on stats.SE that has been unanswered for over a month. That question had a bounty that ended on

“Multiple definition of node a” error in Winbugs

牧云@^-^@ 提交于 2019-12-02 18:11:44
问题 okay i just rewrite my code. Now the problem is when i compile it, I get an error of "multiple definition of node a" . Do anyone know what wrong in my code. I create the variable a,b and c for the model not to have many constants. model{ for(i in 1:n){ a <- (k[1] + step(s1[i]-.9)*k[2] + step(s1[i]*.5-.9)*k[3]) b <- (r[1] + step(s2[i]-.9)*r[2] + step(s2[i]*.5-.9)*r[3]) c <- (s[1] + step(s3[i]-.9)*s[2] + step(s3[i]*.5-.9)*s[3]) dummy[i] <- 0 dummy[i] ~ dloglik(logLike[i]) # This is the log

“Multiple definition of node a” error in Winbugs

点点圈 提交于 2019-12-02 11:48:31
okay i just rewrite my code. Now the problem is when i compile it, I get an error of "multiple definition of node a" . Do anyone know what wrong in my code. I create the variable a,b and c for the model not to have many constants. model{ for(i in 1:n){ a <- (k[1] + step(s1[i]-.9)*k[2] + step(s1[i]*.5-.9)*k[3]) b <- (r[1] + step(s2[i]-.9)*r[2] + step(s2[i]*.5-.9)*r[3]) c <- (s[1] + step(s3[i]-.9)*s[2] + step(s3[i]*.5-.9)*s[3]) dummy[i] <- 0 dummy[i] ~ dloglik(logLike[i]) # This is the log transformation of the 3-variate poisson logLike[i] <- -theta12[i] + a*log(theta12[i]) - logfact(a) -theta13

Choosing Different Distributions based on if - else condition in WinBugs/JAGS

允我心安 提交于 2019-12-01 16:46:12
I am trying to write a Winbugs/Jags model for modeling multi grain topic models (exactly this paper -> http://www.ryanmcd.com/papers/mg_lda.pdf ) Here I would like to choose a different distribution based on a particular value. For Eg: I would like to do something like `if ( X[i] > 0.5 ) { Z[i] ~ dcat(theta-gl[D[i], 1:K-gl]) W[i] ~ dcat(phi-gl[z[i], 1:V]) } else { Z[i] ~ dcat(theta-loc[D[i], 1:K-loc]) W[i] ~ dcat(phi-loc[z[i], 1:V]) } ` Is this possible to be done in Winbugs/JAGS? Winbugs/JAGS is not a procedural language, so you cannot use the construct like that. Use step function. Quote

BUGS error messages

三世轮回 提交于 2019-11-30 03:59:22
I am new to WinBUGS/OpenBUGS and having difficulty debugging my code. Does anyone know of a list of potential error messages for BUGS models and their meanings in plain English? The WinBUGS manual has a list of some common error. I have added some additional notes from my own experience: expected variable name indicates an inappropriate variable name. I occasionally get this error in providing the data, might have used 1.02e04 instead of 1.02E04 . undefined variable - variables in a data file must be defined in a model (just put them in as constants or with vague priors). If a logical node is