# Tag Info

24

I don't know of a canned list. Here is my list (edits provided by original questioner): Normal and log-normal are parameterized in terms of $\tau$ (precision) rather than $\sigma$ or $\sigma^2$ (std. dev. or variance); $\tau = 1/\sigma^2 = 1/\mbox{var}$ Beta, Poisson, Exponential, Uniform are all the same Negative binomial in BUGS has only the discrete ...

19

BUGS/OpenBugs has a peculiar build system which made compiling the code difficult to impossible on some systems --- such as Linux (and IIRC OS X) where people had to resort to Windows emulation etc. Jags, on the other hand, is a completely new project written with standard GNU tools and hence portable to just about anywhere --- and therefore usable ...

12

Since L1 regularization is equivalent to a Laplace (double exponential) prior on the relevant coefficients, you can do it as follows. Here I have three independent variables x1, x2, and x3, and y is the binary target variable. Selection of the regularization parameter $\lambda$ is done here by putting a hyperprior on it, in this case just uniform over a ...

7

By default, JAGS will initialize all elements of alpha0 to the prior mean 0. So the initial value of p is c(0.5, 0, 0, 0.5). Under these prior conditions, it is impossible to have y[i] equal to 2 or 3. But, in your simulated data, y[3] = 3. The solution is to initialize the elements of alpha0 to distinct values inits <- list("alpha0" = c(-0.5, 0, 0.5)) ...

7

The beta regression approach is to reparameterize in terms of $\mu$ and $\phi$. Where $\mu$ will be the equivalent to y_hat that you predict. In this parameterization you will have $\alpha=\mu\times\phi$ and $\beta=(1-\mu) \times \phi$. Then you can model $\mu$ as the logit of the linear combination. $\phi$ can either have its own prior (must be greater ...

6

Usually you can do the predictions in JAGS. Below is a regression example with FEV (something to do with lung capacity) as the dependent variable and age and smoking indicator as predictors. FEV20s and FEV20ns are the predicted FEV values for a 20 year old smoker and a 20 year old non-smoker. model { for(i in 1:n){ FEV[i] ~ dnorm(mu[i],tau) ...

6

Greg Snow gave a great answer. For completeness, here is the equivalent in Stan syntax. Although Stan has a beta distribution that you could use, it is faster to work out the logarithm of the beta density yourself because the constants log(y) and log(1-y) can be calculated once at the outset (rather than every time that y ~ beta(alpha,beta) would be called). ...

6

There is no essential Bayesian / frequentist divide with a correlation any more than there is a Bayesian equivalent of a mean or median. A correlation is just an arithmetic calculation. The need for specific Bayesian techniques only arises when you do inference with it, so the appropriate Bayesian approach would depend on what your actual question is. But ...

5

Here's the notation I'm going to use for the sigmoid model: $y = U + \frac{L - U}{1 + (\frac{x}{x_0})^k}$ The problem is that the sigmoid model nests functions that are close to linear within a bounded domain, and further, that very different parameter values give rise to almost-lines that are almost the same. Check it out: sigmoid <- function(x, L, U, ...

5

Sure, parents of latent variables can be observed. The graph just encodes conditional independence relationships among variables, and is totally separate from the question of which variables are observed or latent. For example, if the graph is $X \to Y \to Z$, this tells you that the density $f(x,y,z)$ factors as $f(x) f(y|x) f(z|y)$, but doesn't tell you ...

5

From (an earlier version of) the Stan reference manual: Not specifying a prior is equivalent to specifying a uniform prior. A uniform prior is only proper if the parameter is bounded[...] Improper priors are also allowed in Stan programs; they arise from unconstrained parameters without sampling statements. In some cases, an improper prior may ...

5

From the Stan reference v1.0.2 (pg 6, footnote 1) If no prior were specified in the model block, the constraints on theta ensure it falls between 0 and 1, providing theta an implicit uniform prior. For parameters with no prior specified and unbounded support, the result is an improper prior. Stan accepts improper priors, but posteriors must be proper in ...

4

Perhaps this is what you are looking for: x_obs[i] ~ dnorm(x_true[i],prec_x)T(x_true[i], ) JAGS has options for both censoring and truncation. It sounds like you want truncation, since you know a-priori that the observation lies within a particular range Read the user's manual for more details about how jags uses truncation and censoring.

4

Doing the algebra, we have $\lambda= (1/b)^a$ (by equating the constant term within the exponent): since $a=\nu$, this is consistent with $a (1/b)^{a} = \nu \lambda$. You're right that my answer elsewhere is wrong; feel free to edit it yourself if I don't get around to it sooner (at least the link is there to warn people) ...)

4

I used a data augmentation procedure suggested here with the following model: model{ for(i in 1:length(y)){ mu[i] <- alpha + beta*x[i] w[i] ~ dexp(tau) me[i] <- (1-2*p)/(p*(1-p))*w[i] + mu[i] pe[i] <- (p*(1-p)*tau)/(2*w[i]) y[i] ~ dnorm(me[i],pe[i]) } #priors for regression alpha ~ dnorm(0,1E-6) beta ~ dnorm(0,1E-6) lsigma ~ ...

4

There are a couple of ways you can do this. The first would be to use the mean of the posterior for each of the $\mu_i$, and calculate a residual using this as the "estimated value" corresponding to $\hat{\beta}X$ in OLS. You then calculate the variance of the residuals as usual and plug it into the $R^2$ calculation. You would do this in R, of course. ...

4

I was asked to re-post this answer here from my comment at http://doingbayesiandataanalysis.blogspot.com/2012/01/complete-example-of-right-censoring-in.html The specifics of this answer relate to the model in that comment, but the concepts apply to the topic here. The core of the JAGS model for censored data is this: isCensored[i] ~ dinterval( y[i] , ...

3

No promises about the computational efficiency of this solution, but the best way to take into account rounding to the nearest integer in JAGS is to use the dinterval "distribution". The JAGS manual includes this passage: The dinterval distribution represents interval-censored data. It has two parameters: t the original continuous variable, and c[], a ...

3

You can avoid this problem altogether by sampling from the untruncated distribution of Y[k], then (in R) discarding all samples for which Y[k] doesn't lie within the constraint bounds. This is a perfectly valid operation, however, if you have few posterior observations in the feasible region, you'll naturally have a large simulation error associated with ...

3

Accelerated BLAS like Goto or Atlas are very useful for speeding up linear algebra operation. That said, common applications programs in R or Jags or ... are typically not bound but the linear algebra performance. The net effect on your particular problem may well be a single digit gain in performance: not shabby, but not earth-shattering either. Most ...

3

(most likely) in one of these lines: denom <- 1 + sum(exp(p)) D1 <- (exp(p[1]))/denom D2 <- (exp(p[2]))/denom D3 <- (exp(p[3]))/denom When the code is running those, part of the contents of p isn't something you want to pass to an exp function. It says "invalid vector argument". Can exp take a vector argument? If it can, maybe that's a ...

3

In the answers there (if I understood correctly) I learned that within-subject variance does not effect inferences made about group means and it is ok to simply take the averages of averages to calculate group mean, then calculate within-group variance and use that to perform significance tests. Let me develop this idea here. The model for the ...

2

I ran your model with rjags package. I have not provided any initial value since JAGS can produce them for you. You can see the error below > m <- jags.model(file = "model.txt", n.chain = 1) Compiling model graph Resolving undeclared variables Deleting model Error in jags.model(file = "model.txt", n.chain = 1) : RUNTIME ERROR: Index out of range ...

2

Thanks for the tips David. I posted this question on the JAGS support forum and got a useful answer. The key was to use a two dimensional array for the 'true' values. for (j in 1:n){ x_obs[j] ~ dnorm(xy_true[j,1], prec_x)T(xy_true[j,1],) y_obs[j] ~ dnorm(xy_true[j,2], prec_y) xy_true[j, ] ~ dmnorm(mu[ z [j],1:2], tau[z[j],1:2,1:2]) ...

2

C <- 10000 #Constant 1/0 trick # Likelihood: for ( i in 1:ny ) { #Likelihood of the count model component LikCountModel[i] <- pow(mu[i],y[i])/y_fact[i]*exp(-mu[i]) #Count model component eta[i] <- bet0 + inprod( beta[] , B[i,] ) mu[i] <- exp(eta[i]) #ZI Component zeta[i] <- gamm0 + inprod( gamma[] , G[i,] ) w[i] <- ...

2

Here is an answer from Martyn Plummer: As written, your model does not have any observed outcomes. You probably noticed that it runs really really fast. This is because it is forward sampling from the prior. That is why your posterior mean for mu is the same as the prior mean of 0. The variable name "is.censored" is appropriate for left- or right-censored ...

2

So here the answer from the comment: I believe there is no way to directly sample from a scaled distribution in JAGS, except the cases where the scaled distribution can be expressed as a standard distribution. This being said there is trick, the so called "zero trick", but I have not used it so far. It might be useful in your case...

2

It should be somewhere along this line: The first part is the model for the measurements, tau_bp refers to the individual errors here: for (i in 1:n){ bp[i]~dnorm(lambda[j],tau_bp) } The second part is to model the different mean and standard deviation of the different treatments: for (j in 1:4){ lambda[j]~dnorm(mu[j],tau[j]) ... } Then ...

2

Longitudinal and mixed models in BUGS is talked about in Ch. 10 of Bayesian Ideas and Data Analysis. Below is a link to the book website which has some example code. http://www.ics.uci.edu/~wjohnson/BIDA/BIDABook.html

2

Yes, it is really easy to use in BUGS or JAGS! It is actually a pleasure to use it! But do the observations with the missing outcomes also affect parameter estimates? Of course not. The parameters are only affected by the observed outcomes. The missing outcomes (NAs) will not affect anything, actually it is the other way: the missing outcomes will be ...

Only top voted, non community-wiki answers of a minimum length are eligible