Search code examples
linear-regressionstan

Symmetric Regression In Stan


I have to vectors of data points (Gene expression in Tissue A and B) and I want to see, if their is any systematic bias along its magnitude (same expression of Gene X in A and B).

The idea was to build a simple regression model in stan and see how much the posterior for the slope (beta) overlaps with 1.

model {
  for (n in 1:N){  
    y[n] ~ normal(alpha[i[n]] + beta[i[n]] * x[n], sigma[i[n]]);
  }
}

However, depending on which vector is x and which is y, I get different results, where one slope is about 1 and other not (see Image, where x and y a swapped and the colored lines represents the regressions I get from the model (gray is slope 1)). As I found out, this a typical thing for regression methods like ordinary least squares, which makes sense if one value is dependent on the other. However, here there is no dependency and both vectors are "equal".

enter image description here

Now the question is, what would be an appropriate model to perform a symmetrical regression in stan.


Following the suggestion from LukasNeugebauer by standardizing the data first and working without an intercept, does not solve the problem.

enter image description here


Solution

  • I cheated a bit and found a solution:

    When you rotate the coordinate system by 45 degrees, the new y-Axis (y') represents the information of x and y in equal amounts. Therefor, assuming a variance only on the new y-Axis involves both x and y.

    x' =  x*cos((pi/180)*45) + y*sin((pi/180)*45)
    y' = -x*sin((pi/180)*45) + y*cos((pi/180)*45)
    

    The above model now results in symmetric results. Where a slope of 0, represents a slope of 1 in the old system.

    enter image description here