Multiple linear regression with t student

This is the code used for a multiple regression with a t student for a robust result, but what if i use more than one predictor? what should i modify in this code? can you help me?

data {
    int<lower=1> Ntotal ;
    real x[Ntotal] ;
    real y[Ntotal] ;
    real meanY ;
    real sdY ;
    real meanX ;
    real sdX ;
  }
  transformed data {
    real unifLo ;
    real unifHi ;
    real expLambda ;
    real beta0sigma ;
    real beta1sigma ;
    unifLo <- sdY/1000 ;
    unifHi <- sdY*1000 ;
    expLambda <- 1/30.0 ;
    beta1sigma <- 10*fabs(sdY/sdX) ;
    beta0sigma <- 10*fabs(meanX*sdY/sdX) ;
  }
  parameters {
    real beta0 ;
    real beta1 ;
    real<lower=0> nu ; 
    real<lower=0> sigma ; 
  }
  model {
    sigma ~ uniform( unifLo , unifHi ) ; 
    nu ~ exponential( expLambda ) ;
    beta0 ~ normal( 0 , beta0sigma ) ;
    beta1 ~ normal( 0 , beta1sigma ) ;
    for ( i in 1:Ntotal ) {
      y[i] ~ student_t( nu , beta0 + beta1 * x[i] , sigma  ) ;
    }
  }

in r i use this code for the data
dataList = list(
x = x ,
y = y ,
Ntotal = length(y) ,
meanY = mean(y) ,
sdY = sd(y) ,
meanX = mean(x) ,
sdX = sd(x)
)

but x is a vector here, i want a matrix cause of multiple predictor, thanks in advance

If X is a matrix and beta is a vector, then vector[N] mu = alpha = X * beta.

1 Like

i mean, the code in the stan part is for an x vector, one predictor, if i have a matrix with multiple predictor
real meanX ;
real sdX ;
are not scalar, what should i modify in the code for making a robust linear regression? are there any guide for changint it? iā€™m terribly in trouble about this thing.

You data block needs to have

matrix[N, K] X;

in it rather than the real array that you have now.

true, thanks, but in datalist? i have
meanX = mean(x) ,
sdX = sd(x)

that doesnt work with matrix

x = x does if x is a matrix