Given y
the dependent variable nx1
and X
the matrix of dimension nxp
of independent variables. I am willing to estimate beta coefficients, r-squared, and others linear regression parameters with a given covariance matrix or by defining my own covariance matrix's estimation method. Is there any Matlab function that allows to do that?
Asked
Active
Viewed 89 times
0

Barbab
- 266
- 1
- 8
1 Answers
0
Ok, this is what I've written:
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)
% - intercept -> if true intercept is included (default)
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
- 266
- 1
- 8