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.

```
## 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!

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).

1 Like

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!

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 has a lot of resources, and you can find some tutorials in the Stan pages. The documentation and user guide examples can also be useful. In case you haven’t seen it before, 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).

1 Like

Thanks, I will work on this!

1 Like