Menu
  • HOME
  • TAGS

OpenBUGS error messages:Expected the collection operator c

Tag: bayesian,winbugs,winbugs14

I could not get the code below to work. it is a hierarchical one way ANOVA model, but when I click data load the error message that appears is expected the collection operator c. What does that mean? Can anyone please help me work the code below please? My data set is bigger, but to simplify the question I am only working here with season=4 (number of groups) and n=5 (number of subjects in each group).

model{
for(i in 1:n){
    Length[i] ~ dnorm(mu.l[i], tau[1]) 
    mu.l[i] <- alpha[j[i]]
}
for (p in 1:J){
    alpha[p]~dnorm(mu, tau[2])
}
mu~dnorm(0,0.0001)
for(k in 1:2){
    tau[k]<-pow(sigma[k],-2)
    sigma[k]~dunif( 0, 10)
}
}

#initials    
list( ort=1.0, alpha=c(NA, 0,0,0), tau=c(1 ,1))  

#Data
list(n=5, j=4)  
j[] length[]  
1   17.00
1   17.50
1   17.50
1   16.20
1   18.00
2   13.70
2   17.4
2   17.70
2   16.40
2   17.70
3   16.4
3   15.00
3   19.60
3   14.70
3   18.00
4   18.20
4   13.60
4   17.30
4   17.3
4   14.5  

Best How To :

A few problems in your code.

  1. In your model you have J and Length. In your data you have j (twice) and length, i.e. no Length or J.

  2. In your initial values you have ort which is not a parameter used anywhere in the model and tau which is not stochastic (perhaps you mean sigma?).

Your model above should work with the following (whether it is the model you want or not is for you to decide):

#Initials
list( alpha=c(NA, 0,0,0))  

#Data
list(n=5, J=4, j=c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4), Length=c(17,17.5,17.5,16.2,18,13.7,17.4,17.7,16.4,17.7,16.4,15,19.6,14.7,18,18.2,13.6,17.3,17.3,14.5))

Bayesian IRT Model in Python using pymc

python,bayesian,pymc

You have been bit by a sneaky part of Python. The global import of pymc replaced your numpy exp with a different exp. To get the exp you want, you can use np.exp in your sigmoid deterministic. (Where did np. come from, I wonder?) return np.exp(1.0 / (1.0 + np.exp(bs...

Examples/tutorials of Adaptive Metropolis for images using PyMC

image-processing,python-3.x,bayesian,pymc

The closest I know of is here: http://nbviewer.ipython.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter5_LossFunctions/LossFunctions.ipynb (see Example: Kaggle contest on Observing Dark World) On this thread you asked a specific question: https://github.com/pymc-devs/pymc/issues/653 about finding an array in an image. Here is a first attempt at a model: In that case it seems like you are trying to...

Naive Bayesian Classification score in percentage

c#,classification,bayesian

If I understand you correctly, you need to sum all Values in the Dictionary, it will give you 100%. Then divide each Value on the received sum. Insert this code before return score;: double sum = score.Values.Sum(); foreach (var name in score.Keys) { score[name] /= sum; } ...

Maximum Likelihood Parameter Estimation

machine-learning,bayesian,mle

Assuming a multinomial distribution for your Color and Size variables, you need to estimate the following parameters : For color: : red probability. : white probability. For size: : probability of being big given being red. : probability of being big given being white. : probability of being small given...

How to speed up scrolling speed of PDF pages with large data plots (e.g. trace plots)

r,pdf,plot,knitr,bayesian

I would recommend you dump the images not as pdf, but as png. If you ensure that the png has a high enough resolution, it will be hard to see the difference between the pdf and the png. The png will be much faster than the pdf, speeding up scrolling.

WinBUGS message error: Expected key word structure

winbugs

xij looks to be matrix in the BUGS model, but you have at as a vector in the data. This should work: list(n=2, k=5, yij=structure(.Data=c(1, 1, 1, 1, 1, 0, 0, 0, 0, 0), .Dim=c(2,5)), xij = structure(.Data=c(0.0494063719, -0.078101264, 0.2748560749, 0.1245743393, -2.531242809, .6849338859, 0.5302062384, 0.7828560148, -0.012341452, 0.5128471157), .Dim=c(2,5)), ui =...

How to simulate quantities of interest using arm or rstanarm packages in R?

r,bayesian,stan

In the case of bayesglm, you could do sims <- arm::sim(m1.arm, n = 1000) y_sim <- rnorm(n = 1000, mean = [email protected] %*% t(as.matrix(s1)), sd = [email protected]) mean(y_sim) For the (unreleased) rstanarm, it would be similar sims <- as.matrix(m1.stan) y_sim <- rnorm(n = nrow(sims), mean = sims[,1:(ncol(sims)-1)] %*% t(as.matrix(s1)), sd...

Optimization error for pymc3

bayesian,pymc,multi-level,pymc3

The error means the optimization algorithm finished but returned values that don't make any sense. Usually this is because the maximum isn't well defined. However, this actually worked fine for me. What versions do you have? I have python 2.7, latest pymc3, theano 0.7.0, scipy 0.13...

How to understand the “calculate the priors based on occurence in the training set” in the function

matlab,machine-learning,bayesian

The "prior" is the "prior distribution", which is the distribution describing the likelihood of each class. This is relevant when it comes time to look at a new data point and, based on your training data, to decide which class it is. If you know a priori that one class...

Naive Bayesian for rating

algorithm,machine-learning,bayesian

Columns "Size" and "Price" represent categorical data (well, actually, ordinal, but that's another point). While you do can model "Rating" as categorical value too, it may be bad idea and it'd much better to model your data as numerical. And here's why. The difference in treating data as categorical and...

Select Features for Naive Bayes Clasification in R

r,bayesian

This error appears to be due to the ldaFuncs. Apparently they do not like factors when using matrix input. The main problem can be re-created with your test data using mm <- ldaFuncs$fit(train[2:5], train[,1]) ldaFuncs$pred(mm,train[2:5]) # Error in FUN(x, aperm(array(STATS, dims[perm]), order(perm)), ...) : # non-numeric argument to binary operator...

Multiple Coins from Single Mint Example in PyMC

bayesian,pymc

Not sure what you mean by theta, since there is no theta in your model. Are you referring to the coin-specific probabilities (which are here represented by mint)? You have specified a single probability for all the coins, rather than 4 probabilities. Try modifying your mint parameter to: mint =...

“ People Who Liked this Also Liked ” Query in Mysql PHP

php,mysql,sql,associations,bayesian

You can JOIN back on the Like table and do something like this. SELECT also_like.m_id, COUNT(also_like.m_id) FROM [like] AS did_like JOIN [like] AS also_like ON also_like.u_id = did_like.u_id AND also_like.m_id != did_like.m_id WHERE did_like.m_id = 1 GROUP BY also_like.m_id ORDER BY COUNT(also_like.m_id) Essentially you are getting a list of users...

Update parameters of Bayesian Network with new data

bayesian,bayesian-networks,probability-theory

It's easiest to maintain the joint probability table, and rebuild the CPT from that as needed. Along with the JPT, keep a count of how many examples were used to produce it. When adding the nth example, multiply all probabilities by 1 - 1/n, and then add probability 1/n to...

How to predict healthy of leaf using image processing technique? [closed]

image-processing,classification,bayesian,prediction,matlab-cvst

There are many possible approaches to a problem like this. One common method is the bag-of-features model. Take a look at this example using the Computer Vision System Toolbox in MATLAB.

OpenBUGS error messages:Expected the collection operator c

bayesian,winbugs,winbugs14

A few problems in your code. In your model you have J and Length. In your data you have j (twice) and length, i.e. no Length or J. In your initial values you have ort which is not a parameter used anywhere in the model and tau which is not...

Bayesian Correlation using PyMC

correlation,bayesian,pymc

This uninformative error is due to the way you have organized your data vector. It is 2 rows by n columns, and PyMC expects it to be n rows by 2 columns. The following modification makes this code (almost) work for me: xy = MvNormal('xy', mu=mean, tau=precision, value=data.T, observed=True) I...

Is it possible to define a Stan model in terms of an arbitrary posterior function?

c++,r,bayesian,stan

In a manner of speaking, defining an arbitrary posterior distribution is all you can do in the Stan language. But if you are referring specifically to a posterior distribution that is not a composition of distributions that are already defined in Stan, then you can use the increment_log_prob function to...

Probability: the one true fish

math,machine-learning,probability,bayesian

What you want is the probability of having the right fish given that the detector beeps, which is P(A|B). The P(B|A) = 9999/10000 is the probability of the detector beeping given you have the right fish. However, we don't know if the fish you have is the right one. All...

JAGS: unit-specific time trends

r,bayesian,jags

Your lm example can also be written: m1 <- lm(gdp ~ -1 + rain + factor(ccode) + factor(ccode):year) The equivalent JAGS model would be: M <- function() { for(i in 1:N) { gdp[i] ~ dnorm(yhat[i], sd^-2) yhat[i] <- b0[ccode[i]] + b1*rain[i] + b2[ccode[i]]*year[i] } b1 ~ dnorm(0, 0.001) for (j...

NA/NaN values in bnlearn package R

r,null,nan,bayesian,bayesian-networks

the catnet package can deal with missing data and is designed for discrete data you can get conditional probabilities using cnProb(bnet,which) here is an example rm(list=ls()) ### generate random data (not simply independent binomials) set.seed(123) n.obs <- 10 a1 <- rbinom(n.obs,1,.3) a2 <- runif(n.obs) a3 <- floor(-3*log(.25+3*a2/4)) a3[a3>=2] <- NA...

R: multivariate Bayesian regression with MCMCregress throws an error

r,regression,bayesian

The basic problem is that with the smaller data set you don't have enough information to estimate the parameters in the model (that is, you have no degrees of freedom). If you run a classical linear regression, you'll see the R-squared of your model with the smaller data is 1....

PyMC trace not changing?

python,bayesian,pymc,survival-analysis

For posterity. Thanks to Chris Fonnesbeck for pointing out that the problem was that I did not give W as an argument to idt. This function should be @deterministic def idt(b1=beta, dl0=dL0, W=W): print beta.value fitted = np.exp(np.dot(X, b1) + W[stfips]) yy = (Y[:,:T] * np.outer(fitted, dl0)) return np.transpose(yy) And...

computing cumulative distribution of a conditional probability distribution

numpy,statistics,scipy,bayesian

I don't know what's wrong with that code. But here are a couple of different ideas to try: (1) Just sum the array elements instead of trying to compute the numerical integrals. It is simpler that way. (Summing the array elements is essentially computing a rectangle rule approximation, which as...

Simple Bayesian Network causal independence [closed]

artificial-intelligence,bayesian,bayesian-networks

You first of all apply the Bayes rule and you get: P(A|B) = P(A) * P(B|A) / P(B) then you sum over the values of a to get: P(A|B) = P(A) * P(B|A) / (sum_{a} P(B,a)) and then you apply the chain rule: P(A|B) = P(A) * P(B|A) / (sum_{a}...

Estimating class probabilities with hierarchical random forest models

r,classification,bayesian,random-forest

I'm actually working on a similar issue and have codified an R package that runs randomForest as the local classifier along a pre-defined class hierarchy. you can find it in R-Forge under 'hie-ran-forest'. The package includes two ways to turn the local probabilities into a crisp class. stepwise majority rule-...

StringToWordVector filter weka

java,weka,bayesian

If you have time, watch this video: https://www.youtube.com/watch?v=IY29uC4uem8 It explain the possibilities and what is responsible for...

Sequential updating in PyMC

python,bayesian,pymc,mcmc

The only way sequential updating works sensibly is in two different models. Specifying them in the same model does not make any sense, since we have no posteriors until after MCMC has completed. In principle, you would examine the distribution of theta1 and specify a prior that best resembles it....

How to write a function in Julia when the type the arguments are dependent

julia-lang,bayesian

the type of xx should be the same as the type of bayesian_component right? if you don't want to make xx to be a component of FiniteMixtureModel(this seems to muddy the waters of your type hierarchy), you can explicitly convert the type of xx as a workaround: function gibbs_sampler(fmm::FiniteMixtureModel,...

Machine Learning Algorithm Confusion

machine-learning,svm,bayesian,logistic-regression

This is a trivial linear model, where you don't even fit the weights of the model, but instead use the constant values. Linear models make deficision using cl(x) = sgn(<w,x>+b) = sgn( SUM w_i x_i + b ) where x is your data point (x_i is ith feature). In your...