0

Given: $$ y=\alpha + \beta x $$ The problem on how to get regression coefficients $\alpha, \beta_0, \beta_1,...,\beta_n$ from the covariance matrix is solved here:

Is there a way to use the covariance matrix to find coefficients for multiple regression?

The same problem can be solved without the intercept ($\alpha =0$)?

$$ y=\beta x $$

My MATLAB code:

function [coefficients, intercept] = gvcoef(X,y,CovEst)
%
% Finds coefficients and intercept estimates
% Inputs:
% - y -> dependent variable vector nx1
% - X -> independent variables matrix nxp
% - cov -> given estimate of covariance matrix (cov(X) in OLS)

a = CovEst;

for i=1:size(X,2)
    covariance = cov(y,X(:,i));
    b(i,:)= covariance(1,2);
end

% Coefficients from the covariance matrix
coefficients = linsolve(a,b);

% Intercept
y_bar = mean(y);
x_bar = mean(X,1);
intercept = y_bar - x_bar * coefficients;

end
```
Barbab
  • 67
  • 6
  • 1
    If I understand your question, the solution is the same. Just follow the answer you linked to until they obtain the coefficients. – Heteroskedastic Jim Jun 14 '21 at 14:52
  • I edited my question to include the code I am using. I do not understand why I get the intercept estimate even if I do not include a ones column in the X matrix – Barbab Jun 14 '21 at 15:08

0 Answers0