Problem with obtain regression equation between 2 data sets
显示 更早的评论
I have 2 data sets, I think it would be easy to obtain regression equation with Matlab but I might toght wrong. because I try corecoef and regress but still unable to obtain an equation to use. I saw some other 3rd party function in fileexchange but I would like to use matlab classic functions.
here my summary till now:
when I use corecoff I get this results that I dont know what that means

also I should use this code because my data sets contains some NaNs
R = corrcoef(Ahvaz_Dec.tmax_m, Ramhormoz_Dec.tmax_m,'rows','complete');
then I searched again and found regress function when I use it by this code:
R = regress(Ahvaz_Dec.tmax_m, Ramhormoz_Dec.tmax_m);
it gaves me a number 0.9911 that I dont understand what is it and why it is'nt similar to corecoef!
I even tried polyfit using this code:
P=polyfit(Ahvaz_Dec.tmax_m, Ramhormoz_Dec.tmax_m,1);
that it gaves me just two NaN values in a cell.
Also, I used this code below:
model = fit(Ahvaz_Dec.tmax_m, Ramhormoz_Dec.tmax_m,'poly1')
figure
plot(model,Ahvaz_Dec.tmax_m,Ramhormoz_Dec.tmax_m)
but it gaves me the following error:
Error using fit>iFit (line 232) X, Y and WEIGHTS cannot have NaN values. Error in fit (line 116) [fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...re
So I want to ask you if you please guide me on how to obtain one linear regression equation between these 2 data sets.
2 个评论
the cyclist
2020-1-26
Can you upload the dataset in a MAT file, so that we can test it ourselves?
BN
2020-1-27
采纳的回答
更多回答(1 个)
the cyclist
2020-1-27
编辑:the cyclist
2020-1-27
All these methods will give the same coefficient for the y/x sloped if you scale the variables first:
rng default
N = 10;
x = randn(N,1);
y = randn(N,1);
xscale = (x-mean(x))./std(x);
yscale = (y-mean(y))./std(y);
polyfit(xscale,yscale,1)
regress(yscale,[ones(N,1) xscale])
r = corrcoef(xscale,yscale)
regress and polyfit will give the same answer as each other on either scaled or unscaled data.
corrcoef will give the same correlation coefficient on either scaled or unscaled data, but it will be different from regress and polyfit for unscaled.
But, you do need to manage the NaNs, as Adam has pointed out.
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!