# Updating Gaussian multiple regression code and building a robust model

**URL:** <https://discourse.mc-stan.org/t/updating-gaussian-multiple-regression-code-and-building-a-robust-model/22445>\
**Category:** Modeling\
**Tags:** rstan\
**Created:** [May 12, 2021, 4:46pm UTC](https://discourse.mc-stan.org/t/updating-gaussian-multiple-regression-code-and-building-a-robust-model/22445 "2021-05-12T16:46:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![oleksiy](https://avatars.discourse-cdn.com/v4/letter/o/2bfe46/32.png) [@oleksiy](https://discourse.mc-stan.org/u/oleksiy)\
**Post date:** [May 12, 2021, 4:46pm UTC](https://discourse.mc-stan.org/t/updating-gaussian-multiple-regression-code-and-building-a-robust-model/22445/1 "2021-05-12T16:46:44Z")

</div>

I am super new to this and apologize in advance for a very basic question. This is my second question with the same code.  
I am fitting a basic multiple regression model, [using this code](https://rpubs.com/kaz_yos/stan-lm1).

```
## data {
## // Define variables in data
## // Number of observations (an integer)
## int<lower=0> N;
## // Number of parameters
## int<lower=0> p;
## // Variables
## real wt82_71[N];
## int<lower=0> qsmk[N];
## int<lower=0> sex[N];
## real<lower=0> age[N];
## int<lower=0> race[N];
## real<lower=0> smokeyrs[N];
## }
## 
## parameters {
## // Define parameters to estimate
## real beta[p];
##   
## // standard deviation (a positive real number)
## real<lower=0> sigma;
## }
## 
## transformed parameters {
## // Mean
## real mu[N];
## for (i in 1:N) {
## mu[i] <- beta[1] + beta[2]*qsmk[i] + beta[3]*sex[i] + beta[4]*age[i] + beta[5]*race[i] + beta[6]*smokeyrs[i]; 
## }
## }
## 
## model {
## // Prior part of Bayesian inference (flat if unspecified)
## 
## // Likelihood part of Bayesian inference
## wt82_71 ~ normal(mu, sigma);  
## }

```

How to transform this Stan code into the robust model?

Thanks!

---

<div class="post-metadata">

**Author:** ![caesoma](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/caesoma/32/19767_2.png) [@caesoma](https://discourse.mc-stan.org/u/caesoma)\
**Post date:** [May 12, 2021, 8:35pm UTC](https://discourse.mc-stan.org/t/updating-gaussian-multiple-regression-code-and-building-a-robust-model/22445/2 "2021-05-12T20:35:04Z")

</div>

Don’t worry. Everyone was new at this at some point. Are you reproducing the analysis in that page exactly, and is something not working as expected?

As a first improvement, one possibility is using some priors on the parameters (although that is not required to get good results).

---

<div class="post-metadata">

**Author:** ![oleksiy](https://avatars.discourse-cdn.com/v4/letter/o/2bfe46/32.png) [@oleksiy](https://discourse.mc-stan.org/u/oleksiy)\
**Post date:** [May 12, 2021, 8:45pm UTC](https://discourse.mc-stan.org/t/updating-gaussian-multiple-regression-code-and-building-a-robust-model/22445/3 "2021-05-12T20:45:47Z")

</div>

Dear @caesoma, I am trying to use this exact code and update it, building a robust model.  
I tried multiple options, trying to incorporate `nu` and `student_t()` there, but so far no luck. If you can help me to adapt this code, I would be super grateful!

---

<div class="post-metadata">

**Author:** ![caesoma](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/caesoma/32/19767_2.png) [@caesoma](https://discourse.mc-stan.org/u/caesoma)\
**Post date:** [May 12, 2021, 10:54pm UTC](https://discourse.mc-stan.org/t/updating-gaussian-multiple-regression-code-and-building-a-robust-model/22445/4 "2021-05-12T22:54:43Z")

</div>

The applications of linear regression vary wildly, so what a robust model is really depends on the specifics and the amount and quality of data you have. Since you mention you are new at this, the best way to get started is with some tutorials – the Stan [Youtube channel](https://www.youtube.com/watch?v=UQtFkEOg9SM) has a lot of resources, and you can find some [tutorials](https://mc-stan.org/users/documentation/tutorials) in the Stan pages. The documentation and user guide examples can also be useful. In case you haven’t seen it before, [brms](https://mc-stan.org/users/interfaces/brms) is a Stan application that is specific to all kinds of linear regression, if you are used to the linear regression of R it’s supposed to look familiar.

It may take a while to fel confident about building your own models, but you should take your time to walk through several examples and understand why certain choices are made. Whenever you have a specific issue you cannot understand in any of those resources the community here can help you get through it – but it works best when it’s a specific issue because of the format here and the availability to explain issues in detail (if the answer gets too large, may a new tutorial has to be written).

---

<div class="post-metadata">

**Author:** ![oleksiy](https://avatars.discourse-cdn.com/v4/letter/o/2bfe46/32.png) [@oleksiy](https://discourse.mc-stan.org/u/oleksiy)\
**Post date:** [May 12, 2021, 11:26pm UTC](https://discourse.mc-stan.org/t/updating-gaussian-multiple-regression-code-and-building-a-robust-model/22445/5 "2021-05-12T23:26:06Z")

</div>

Thanks, I will work on this!
