jags

How to model a mixture of finite components from different parametric families with JAGS?

喜你入骨 提交于 2020-01-04 07:37:06
问题 Imagine a underlying process that draws a number from a normal distribution with probability $\alpha$ and from a uniform distribution with probability $1 - \alpha$. The observed sequence of numbers generated by this process therefore follows a distribution $f$ that is a mixture of 2 components and mixing weights of $\alpha$ and $1 - \alpha$. How would you model this kind of mixture with JAGS when the observed sequence is the only input, but the parametric families are known? Example (in R):

JAGS model with error “Node inconsistent with parents”

谁都会走 提交于 2019-12-25 09:28:08
问题 I have written an Item response model in R JAGS. It is basically a multilogit model with latent factors. But I received the following error message: Error in jags.model(model1.spec, data = list(Y = test, n = nrow(test), : Error in node Y[1,1] Node inconsistent with parents Here are my model code: model{ # Subject i for (i in 1:n){ # Test j; test j has K[j] possible scores for (j in 1:p){ Y[i,j]~dcat(prob[i,j,1:K[j]]) } # Underlying patient ability theta[i]~dnorm(0,1) for (j in 1:p){ for (k in

JAGS Poisson count censored data

偶尔善良 提交于 2019-12-24 13:32:36
问题 R, Bayestats and Jags newbie here. I'm working on modeling some count data, right censored. Poisson seems to be my best guess. I wanna do a hierarchical model, as it leaves me with more possibilities to fine tune the parameterss. Can I simply write something like this: A[i,j] <- dpois(a[i,j]) a[i,j]) <- b[i,]*x[i,j] +c[i] for all j, where x[i,j] are my variables, or should I separate the censored time interval from the previous ones or something? b[,] and c have a prior. Thank you! 回答1: This

How to load rjags

狂风中的少年 提交于 2019-12-23 00:42:09
问题 As with a lot of other people, I have issues loading and installing rjags. I get the error: library(rjags) Error : .onLoad failed in loadNamespace() for 'rjags', details: call: fun(libname, pkgname) error: Failed to locate any version of JAGS version 3 The rjags package is just an interface to the JAGS library Make sure you have installed JAGS-3.0.0.exe or higher from http://www.sourceforge.net/projects/mcmc-jags/files Error: package or namespace load failed for ‘rjags’ I am running R 3.2.2

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

好久不见. 提交于 2019-12-19 17:32:16
问题 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? 回答1: Winbugs

strange jags.parallel error / avoiding lazy evaluation in function call

ⅰ亾dé卋堺 提交于 2019-12-18 08:57:40
问题 I have a function call (to jags.parallel ) that works when given a numerical argument like n.iter = 100 but fails when the argument uses a variable value, n.iter = n.iter . This looks like it might be a bug in jags.parallel A minimal reproducible example of the error: library(R2jags) model.file <- system.file(package="R2jags", "model", "schools.txt") J <- 8.0 y <- c(28.4,7.9,-2.8,6.8,-0.6,0.6,18.0,12.2) sd <- c(14.9,10.2,16.3,11.0,9.4,11.4,10.4,17.6) jags.data <- list("y","sd","J") jags

Fitting a multivariate dirlichet model in JAGS for R

家住魔仙堡 提交于 2019-12-14 01:28:35
问题 I am trying to fit a a multivariate model to species composition data using JAGS, implemented in R. I have data on 3 species relative abundances (bounded between [0,1]), two of which are correlated. Here is code to generate similar data. #generate some correlated fractional composition data. y1 <- runif(100,10,200) y2 <- y1*1.5 + rnorm(100, sd = 5) y3 <- runif(100,10,200) total <- y1+y2+y3 y1 <- y1/(total) y2 <- y2/(total) y3 <- y3/(total) y <- data.frame(y1,y2,y3) y is a data.frame of my

JAGS and WinBUGS giving differing DIC

孤人 提交于 2019-12-13 16:21:26
问题 I'm doing a network meta-analysis including several clinical trials. The response is binomial. Each trial contains several treatments. When I do a random effects model, the output from JAGS and WinBUGS is similar. When I do a fixed effects model, the DIC and pD components are way out, though the posteriors of the parameters I'm interested in are similar. I've got similar models that have Gaussian response, not binomial, and JAGS and WinBUGS are in agreement. The BUGS/JAGS code for the fixed

Saving jags.model in RData file

别等时光非礼了梦想. 提交于 2019-12-13 02:36:22
问题 Is there any way to save a jags.model() object into a RData or txt file ? To perform MCMC on a better computer, I have to save my model on one and using it in a new workspace. But I've some difficulty to use "save()" and "load()" function on R. Thanks for your advices. Added: I tried: jags <- jags.model('regression.bug', data = my.data, n.chains = 4, n.adapt = 1000) Then I would like save "jags" save( jags , file="jags.RData") It's look like if it's saved. But, when I try: ld.jags <- load(

How to define a temporary local variable in jags?

寵の児 提交于 2019-12-13 01:34:56
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 6 years ago . I want to create a temp variable in jags, but it doesn't work as it would work in R for (cid in 1:CAMPAIGN_N) { for (time in 1:DATE_N){ index <- time * CAMPAIGN_N + cid - 2 positives[index] ~ dbin( k[time]*ctr[cid], tries[index]) } } Gives error, because index variable is being defined only once. So I had to write it the following ugly way: for (cid in 1:CAMPAIGN_N) { for (time