How can I make a linear regression coefficient calculation algorithm

function [alpha, beta] = linreg( x, y )
beta = cov( x, y ) / var( x ) ;
% ...
end
I wrote this code and I cant undestand how can I use thease formules, which I found:

 채택된 답변

Sudarshan
Sudarshan 2022년 12월 7일

0 개 추천

Hi Ihor,
Based on the equations, you have already calculated the “beta” value. Now, all you need to do is find the mean value of the vectors x and y (the second equation), and then use them to calculate the alpha value.
To calculate the mean value of the vectors, use the “mean” function documentation below:
You will need to iteratively find the correct “alpha” and “beta” values that fit for the vectors “x” and “y”. To understand linear regression better, refer to the linear regression documentation below:

추가 답변 (0개)

카테고리

질문:

2022년 12월 4일

답변:

2022년 12월 7일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by