Questions tagged [mcmc]

Markov chain Monte Carlo (MCMC) methods are a class of algorithms for sampling from a probability distribution based on constructing a Markov chain that has the desired distribution as its equilibrium distribution. The state of the chain after a number of steps is then used as a sample of the desired distribution

Source Wikipedia

493 questions
32
votes
7 answers

Import a module with parameter in python

Is it possible to import a module with some parameter in python ? All I mean by parameter is that there exists a variable in the module which is not initialized in that module, still I am using that variable in that module. In short, I want behavior…
turing
  • 577
  • 1
  • 4
  • 12
29
votes
1 answer

PyMC: Taking advantage of sparse model structure in Adaptive Metropolis MCMC

I have a model that is structured as in this diagram: I have a population of several people (indexed 1...5 in this picture). Population parameters (A and B, but there can be more) determine the distributions for each individual's latent variable…
Danny
  • 450
  • 4
  • 10
21
votes
1 answer

How does pymc represent the prior distribution and likelihood function?

If pymc implements the Metropolis-Hastings algorithm to come up with samples from the posterior density over the parameters of interest, then in order to decide whether to move to the next state in the markov chain it must be able to evaluate…
user18297
  • 323
  • 2
  • 7
17
votes
8 answers

Is Matlab (vs. C/FORTRAN) a respectable language for a professional mathematical researcher of the 21st century?

I am a die hard user of matlab, mostly because this is what I learned first and I have not encountered a problem with a significant enough difference to switch. I come from numerical optimization/linear algebra, where I have performed optimization…
mr matlab
  • 179
  • 1
  • 1
  • 3
15
votes
2 answers

Maximize a function with many parameters (python)

first, let me say that I lack experiences with scientific math or statistics - so this might be a very well-known problem, but I don't know where to start. I have a function f(x1, x2, ..., xn) where I need to guess the x'ses and find the highest…
David
  • 153
  • 1
  • 1
  • 5
10
votes
6 answers

how to incorporate C or C++ code into my R code to speed up a MCMC program, using a Metropolis-Hastings algorithm

I am seeking advice on how to incorporate C or C++ code into my R code to speed up a MCMC program, using a Metropolis-Hastings algorithm. I am using an MCMC approach to model the likelihood, given various covariates, that an individual will be…
user1201814
  • 101
  • 3
9
votes
0 answers

Bayesian error-in-variables (total least squares) model in R using MCMCglmm

I am fitting some Bayesian linear mixed models using the MCMCglmm package in R. My data includes predictors that are measured with error. I'd therefore like to build a model that takes this into account. My understanding is that a basic mixed…
Alberto
  • 133
  • 5
9
votes
3 answers

How to make a truncated normal prior: converting pymc2 to pymc3

In pymc3 how does one configure a truncated normal prior? In pymc2 it's pretty straightforward (below), but in pymc3 it seems there is no longer a truncated normal distribution available. Pymc2: TruncatedNormal('gamma_own_%i_' % i, mu=go,…
Kemp
  • 91
  • 6
8
votes
1 answer

MCMCglmm multinomial model in R

I'm trying to create a model using the MCMCglmm package in R. The data are structured as follows, where dyad, focal, other are all random effects, predict1-2 are predictor variables, and response 1-5 are outcome variables that capture # of observed…
M.A.Kline
  • 1,697
  • 2
  • 19
  • 29
8
votes
0 answers

Fitting a non-homogeneous poisson-process with PyMC

I'm new to PyMC and trying to fit my non-homogeneous poisson-process with a piecewise-constant rate function using the maximum a posteriori estimate. My process describes some events during a day. Therefore i'm splitting a day into 24 hours, which…
sascha
  • 32,238
  • 6
  • 68
  • 110
7
votes
1 answer

How to extract stan code from rstanarm object

Is there a possibility to extract the stan code used for the MCMC sampling in rstanarm? I would like to compare my own parametrisation of a model and prior choices to the one used in rstanarm.
snaut
  • 2,261
  • 18
  • 37
7
votes
3 answers

How to properly sample truncated distributions?

I am trying to learn how to sample truncated distributions. To begin with I decided to try a simple example I found here example I didn't really understand the division by the CDF, therefore I decided to tweak the algorithm a bit. Being sampled is…
Alexander Cska
  • 738
  • 1
  • 7
  • 29
7
votes
1 answer

Is it possible to run multiple chains with JAGS on multiple cores (subdividing chains)

I’m wondering if it’s possible to subdivide 3 chains in JAGS on 5 or 6 cores, for example. Here is my code: library(parallel) # There is no progression bar using parallel jags.parallel(data = d$data, inits =…
M. Beausoleil
  • 3,141
  • 6
  • 29
  • 61
7
votes
1 answer

pymc3: hierarchical model with multiple obsesrved variables

I have a simple hierarchical model with lots of individuals for which I have small samples from a normal distribution. The means of these distributions also follow a normal distribution. import numpy as np n_individuals = 200 points_per_individual…
DanT
  • 3,960
  • 5
  • 28
  • 33
7
votes
2 answers

Solving inverse problems with PyMC

Suppose we're given a prior on X (e.g. X ~ Gaussian) and a forward operator y = f(x). Suppose further we have observed y by means of an experiment and that this experiment can be repeated indefinitely. The output Y is assumed to be Gaussian (Y ~…
juliohm
  • 3,691
  • 2
  • 18
  • 22
1
2 3
32 33