- Is there a routine to perform quantile regression or LAD (Least Absolute Deviations) in MATLAB?
- Least Absolute Value based regression
how to create a linear regression in least squares method and Least absolute value method, and find the correlation coefficients.
3 次查看(过去 30 天)
显示 更早的评论
I would like to create a linear regression in a scatter plot which are created by following code in two methods, least squares method and Least absolute value method, and I find the correlation coefficients. I want to create a linear regression from all of the plot, not for each data set. If you have good idea, please give me advice.
following my code;
for i = 1:12
hold on
if i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12
for j = 1:31
xfilename = sprintf('TA2004%02d%02d.txt',i,j);
yfilename = sprintf('TS2004%02d%02d.txt',i,j);
x = load(xfilename);
y = load(yfilename);
if i==1 && j == 1
scatter(x,y);
else
scatter(x,y);
end
end
elseif i==2
for j = 1:29
xfilename = sprintf('TA2004%02d%02d.txt',i,j);
yfilename = sprintf('TS2004%02d%02d.txt',i,j);
x = load(xfilename);
y = load(yfilename);
scatter(x,y);
end
else
for j = 1:30
xfilename = sprintf('TA2004%02d%02d.txt',i,j);
yfilename = sprintf('TS2004%02d%02d.txt',i,j);
x = load(xfilename);
y = load(yfilename);
scatter(x,y);
end
end
hold off
end
xlabel('surface temperature');
ylabel('near-surface air temperature');
0 个评论
回答(1 个)
michio
2016-10-10
As far as I know, MATLAB does not have least absolute value method implemented. Related answers are
It seems that you have two text files for each day in 2004 (366x2=732 files). If you are looking at getting some statistics from data, instead of just visualizing them (eg. scatter, histogram), I'd suggest you import all of the data (if RAM allows, it seems it does) then use functions like polyfit and corrcoef.
There are multiple ways to achieve this, but if you are using R2014b or later, I strongly recommend using datastore functionality. See Getting started with datastore.
If the data format allows, your data import becomes as simple as the following four lines.
dsX = datastore('TA2004*.txt');
x = readall(dsX);
dsY = datastore('TS2004*.txt');
y = readall(dsY);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!