# How to draw MCMC sample from a model where some random parameters are maintained to their fixed, prior distribution?

Use case:

• step 1: sample from model A with parameter `a` (setups some global parameters)
• step 2: sample from models B_k with parameter `a` and `b_k`, where `a` should be drawn from model A posterior (and should not be updated in model B_k), and `b_k` should be tuned along the way (this applies to various stations that are related to the global parameters, while adding some local effects represented by parameter `b_k`; any new knowledge related to station k should feed into `b_k`). Random variables `a` and `b_k` are multi-dimensional.

FYI, in pymc3, this can be done with a RandomStream with the variable `a` otherwise marked as Deterministic (see thread), so invisible to the NUTS stepping; or via a custom step operating alongside with, but on different parameters than NUTS (see thread and code)

sorry but i’m not really sure what you mean. could you provide a more precise mathematical description? is `a` fixed throughout?

@martinjankowiak sorry I reply only now, I did not see the notification. Let me try to explain better. Let’s forget the `_k` indices for a moment, since it does not influence the mathematics.
I guess what I’d like to achieve is to sample from p(a, b) = p( b | a) * p(a), where p(a) is the posterior distribution from model A. It is practically convenient for me to separate the steps of sampling from the model A posterior first, and feed that result in model B somehow. What I suggest should be equivalent to draw N samples a_i from p(a), and then for each a_i, draw M samples from p(b | a_i), thus yielding N*M samples from p(a, b). I suppose I could do this by just having M=1, but drawing a single sample this way seems inefficient. I was wondering if there is a more efficient way of drawing N samples from p(a, b), building on my N a_i samples from p(a). In pymc, one OK way of doing that is to use a compound step where `a` is sampled from {a_i}, and `b` is using NUTS. Yes, fixed distribution {a_i} throughout.

PS: note this approach is a form of “discretization” of p(a), which is approximated as a fixed collection of samples {a_i}

where do you get the marginal posterior from a? is it an approximation

I have a model A with its own parameters and observations. It represents the contributions to global-mean sea level rise (glaciers melt). The model B represents local processes (e.g. vertical land uplift) that occurs at the coast, which are distinct from the processes described in model A. In this approach, I do not wish the observations at the coast to feedback on, say, what we know about glaciers melt. I wish the model B and coastal observations to only constrain what we know about vertical land movement and other purely local processes, assuming the posterior distribution on global sea level is perfectly known. It’s a safety measure to control the information flow…