multiple linear regression check
Ältere Kommentare anzeigen
Hello Senior Matlab users
Firstly, I want to say sorry for my question as I am a beginner.
I want to ask for good programming advice for my messy code.
In my multiple linear regression example, there are two dependent variables( wind, temperature) and independent variable(evporation) for 10 numbers.
I got coefficients of beta1, beta2 and beta3 and I also checked the answer using calculated beta values. The answer seems correct.
The question is I used many for loops and I don't know how to code in only one for loop and smarter way. I also want to use built in regression function but don't know how to include.
So, if you can advice for my messy code, it would be very helpful for me.
Thank you very much.
clear all;clc;
data = csvread('multiregression.csv');
X = data(:,2:4);
wind= X(:,2);
temp= X(:,3);
Y = data(:,1);
Xt = data(:,2:4)';
Yt = data(:,1)';
beta= ((Xt*X)^-1)*(Xt*Y)
X2= size(X,1);
for i=1:X2
Xq(i)=beta(2)* wind(i);
end
for i=1:X2
Yq(i)= beta(3)*temp(i);
end
beta1= (beta(1)* ones(X2,1));
for i=1:X2
calculated_ans(i)= beta1(i) + Xq(i) + Yq(i);
end
answer= [calculated_ans' Y]
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Linear Regression finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!