# Implementing a robit model in pymc3

**URL:** <https://discourse.pymc.io/t/implementing-a-robit-model-in-pymc3/7094>\
**Category:** Questions\
**Created:** [March 26, 2021, 7:53pm UTC](https://discourse.pymc.io/t/implementing-a-robit-model-in-pymc3/7094 "2021-03-26T19:53:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Yang](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/david_yang/32/3853_2.png) [@David\_Yang](https://discourse.pymc.io/u/David_Yang)\
**Post date:** [March 26, 2021, 7:53pm UTC](https://discourse.pymc.io/t/implementing-a-robit-model-in-pymc3/7094/1 "2021-03-26T19:53:14Z")

</div>

I’m trying to implement a robust logistic regression, using an analogous logic as robust linear regression. I can find STAN implementation (called “Robit”) of this such as the main section of code copied below (original post [here](https://avehtari.github.io/ROS-Examples/Robit/robit.html#Fit_logit_and_probit_models_using_the_simulated_data)):

In the model block, the Bernoulli p is transformed by the Student T cdf. I’m wondering if there is a straight forward way of translating this into pymc3. To my knowledge, there is no student t distribution in the math module and I don’t have enough knowledge to code Theano-compliant math myself.

```auto
data {
  int N;
  vector[N] x;
  int y[N];
  real df;
}
parameters {
  real a;
  real b;
}
model {
  vector[N] p;
  for (n in 1:N) p[n] = student_t_cdf(a + b*x[n], df, 0, sqrt((df - 2)/df));
  y ~ bernoulli(p);
}

```

---

<div class="post-metadata">

**Author:** ![jonsedar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jonsedar/32/2590_2.png) [@jonsedar](https://discourse.pymc.io/u/jonsedar)\
**Post date:** [March 27, 2021, 11:27am UTC](https://discourse.pymc.io/t/implementing-a-robit-model-in-pymc3/7094/2 "2021-03-27T11:27:34Z")

</div>

_R_obit not probit? Strange naming… Anyway, I had to create the cdf and invcdf of a couple of distributions recently, Theano’s generally quite kind to this pursuit. I found the harder part was the actual math!

There’s a StudentT and a Cauchy (equivalent if nu=1) in pymc3 ([Continuous — PyMC3 3.10.0 documentation](https://docs.pymc.io/api/distributions/continuous.html#pymc3.distributions.continuous.StudentT)), both of which have a logcdf. So possibly you could use a dirty hack to exponentiate the logcdf output, or dig into the code to guide your writing of your own cdf function. The Cauchy looks much more pleasant [pymc3/continuous.py at 97b54f0da10074b0f3f62ff7040de2dc7c79a7ad · pymc-devs/pymc3 · GitHub](https://github.com/pymc-devs/pymc3/blob/97b54f0da10074b0f3f62ff7040de2dc7c79a7ad/pymc3/distributions/continuous.py#L2351)

---

<div class="post-metadata">

**Author:** ![petesherick](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/petesherick/32/4662_2.png) [@petesherick](https://discourse.pymc.io/u/petesherick)\
**Post date:** [December 16, 2021, 6:54pm UTC](https://discourse.pymc.io/t/implementing-a-robit-model-in-pymc3/7094/3 "2021-12-16T18:54:47Z")

</div>

Robit = Robust Probit  
So essentially replacing the normal errors with a fatter tail like student’s distribution. I think you should be able to accomplish with a hierarchical latent variable probit model? Just getting my feet wet so I won’t try to share my bad code, just the GLM Hierarchical example:  
[https://docs.pymc.io/en/v3/pymc-examples/examples/generalized\_linear\_models/GLM-hierarchical.html#Hierarchical-Model](https://docs.pymc.io/en/v3/pymc-examples/examples/generalized_linear_models/GLM-hierarchical.html#Hierarchical-Model)
