# Custom prior for isotonic regression

I’m trying to make a bayesian isotonic regression.

I have an unknown function that I’m trying to fit this model too. The x values runs from 0-100 (these are integers) and the y value is an event (0, 1). I want to fit a probability, p(y|x), to this data

As my x value increases the p(y) can only increase or stay the same, which is why I have chosen to use an isotonic regression. The relationship does not follow a known function so fitting a sigmoid or another function won’t work.

I’m planning to start very simply.

``````with pm.Model() as model:
prior = CUSTOMER_PRIOR('prior', )
observed = pm.Bernoulli('observed', p=prior[observed_x], observed=observed_y)
trace = pm.sample(1000)
pm.traceplot(trace)
``````

This is roughly how I expect the code to look. The CUSTOM_PRIOR would sample isotonic functions, which are actually a list of length 101. Each element represents the probability of y for the value Xi where i is 0-100.

First of all does my model my sense or is there a better way to structure it? Secondly, my question is how do I make this custom prior?

I’m not sure you need a custom prior for this. Would it make sense to model this something like:

``````with pm.Model() as model:
y0       = pm.Normal('y0',mu=some_representative_mu,sd=some_representative_sd)
delta    = pm.HalfNormal('delta',sd=some_representative_sd,shape=(length_of_data-1))
y        = theano.tensor.extra_ops.cumsum(theano.tensor.stack([y0,delta]))
observed = pm.Bernoulli('observed', p=y, observed=observed_y)
``````

where I’ve assumed that each delta is independent of the others.