mcmc

PyMC regression of many regressions?

白昼怎懂夜的黑 提交于 2019-12-12 05:49:21
问题 I haven't been using PyMC for long, but I was pleased at how quickly I was able to get a linear regression off the ground (this code should run without modification in IPython): import pandas as pd from numpy import * import pymc data=pd.DataFrame(rand(40)) predictors=pd.DataFrame(rand(40,5)) sigma = pymc.Uniform('sigma', 0.0, 200.0, value=20) params= array([pymc.Normal('%s_coef' % (c), mu=0, tau=1e-3,value=0) for c in predictors.columns]) @pymc.deterministic(plot=False) def linear_regression

RJAGS output Node inconsistent with parents

你说的曾经没有我的故事 提交于 2019-12-12 03:31:22
问题 Hi everyone I'm new in JAGS and currently doing a bayesian inference using mcmc through RJAGS. I've been trying my best to debug my code until I'm stuck with this error "Error in node e1[3] Node inconsistent with parents". e1<-c(1,1,0,1,1,0,0,1,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,1,1,0,0,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,0,1,1,0,0,1,1,1,1,0,1) e2<-c(1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1,0,1,1,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,1,1,1,0,1,1,0,1,1,1,1,1) c1<-c(2412,3485,881,1515,1824,1603,865

R: Alleged “missing values” when no values are actually missing for MCMCglmm

寵の児 提交于 2019-12-12 03:06:48
问题 I have a data structured as follows: A is the count of positive cases in a cohort B is the total count of the cohort minus A . C is a binary variable D - F are normally distributed continuous variables G is 6 level factor I am using MCMCglmm package in R to analyse this data to find which of the variables C - G affect A and B . I have done this successfully using lme4's glmer function with success but now I wish to add more random effects which I have been advised will be better handled by

KeyError while printing trace in PyMC

独自空忆成欢 提交于 2019-12-12 01:39:16
问题 I had read that by default some names are assigned to Stochastic vaiables. I am writing the relevant portion of my code below. lam = pm.Uniform('lam', lower=0.0, upper=5, doc='lam') parameters = pm.Dirichlet('parameters',[1,1,1,1], doc='parameters') rv = [ pm.Multinomial("rv"+str(i), count[i], prob_distribution[i], value = data[i], observed = True) for i in xrange(0, len(count)) ] m = pm.MCMC([lam, parameters, rv]) m.sample(10) print m.trace('lam')[:] print m.trace('parameters_0')[:] The last

MCMCglmm data format difficulties

被刻印的时光 ゝ 提交于 2019-12-11 06:06:20
问题 I want to estimate the heritability of animal traits using an animal model. However, I can't figure out how to properly format my data so that MCMCglmm can create a model. After much trial and error and scouring the internet for advice, I'm stuck. To my knowledge, I've formatted the data as suggested by all available resources that I know of, yet I get the following error message:: Error in MCMCglmm(BWT ~ 1, random = ~animal, pedigree = Ped, data = Data, : some levels of animal do not have a

How can I carry out model simplification for a MCMCglmm?

不羁的心 提交于 2019-12-11 05:47:22
问题 I have a mixed-effects model that I am running in the package MCMCglmm in R. There are several possible predictors that I am interested in exploring. How can I carry out model simplification to exclude uninformative predictors from the model? In other contexts, I have used stepwise backwards regression i.e. starting with a "full" model which contains all of the predictors that I am interested in, and using drop1() to find uninformative variables, followed by update() to remove them from the

R : function to generate a mixture distribution

心不动则不痛 提交于 2019-12-08 21:24:41
问题 I need to generate samples from a mixed distribution 40% samples come from Gaussian(mean=2,sd=8) 20% samples come from Cauchy(location=25,scale=2) 40% samples come from Gaussian(mean = 10, sd=6) To do this, i wrote the following function : dmix <- function(x){ prob <- (0.4 * dnorm(x,mean=2,sd=8)) + (0.2 * dcauchy(x,location=25,scale=2)) + (0.4 * dnorm(x,mean=10,sd=6)) return (prob) } And then tested with: foo = seq(-5,5,by = 0.01) vector = NULL for (i in 1:1000){ vector[i] <- dmix(foo[i]) }

Converting a mixture of gaussians to PyMC3

北慕城南 提交于 2019-12-08 06:43:07
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 5 years ago . I am trying to learn PyMC3, I want to make a simple mixture of gaussians example. I found this example and want to convert it to pymc3 but I'm currently getting an error when trying to plot the traceplot. n1 = 500 n2 = 200 n = n1+n2 mean1 = 21.8 mean2 = 42.0 precision = 0.1 sigma = np.sqrt(1 / precision) # precision = 1/sigma^2 print "sigma1: %s" % sigma1 print "sigma2: %s" %

Meaning of “trait” in MCMCglmm

你。 提交于 2019-12-07 12:53:36
问题 Like in this post I'm struggling with the notation of MCMCglmm , especially what is meant by trait . My code ist the following library("MCMCglmm") set.seed(123) y <- sample(letters[1:3], size = 100, replace = TRUE) x <- rnorm(100) id <- rep(1:10, each = 10) dat <- data.frame(y, x, id) mod <- MCMCglmm(fixed = y ~ x, random = ~us(x):id, data = dat, family = "categorical") Which gives me the error message For error structures involving catgeorical data with more than 2 categories pleasue use

Embedding Stan in C++ application

ⅰ亾dé卋堺 提交于 2019-12-07 10:51:43
问题 I wanted to know whether it is possible to incorporate Stan in another C++ application. Since Stan is also written in C++, there should be a way. Currently, I am using RInside to achieve this but then you have all this data transferring which is time-consuming. 回答1: What specifically did you want from Stan? We're going to separate out the math library into a standalone include for Stan 2.7 --- that contains all the matrix, probability, and autodiff code. Our repos already reflect this