why am i getting zero slope?

2 次查看(过去 30 天)
aine gormley
aine gormley 2018-12-6
评论: Stephen23 2018-12-6
I calculate linear regression (temperature change (y) over 30 years (x)) using a large dataset (producing >55000 slopes). 62% of the slopes are exactly zero, which makes no sense.
Also, although no error comes up, I am getting a warning 'x is rank deficient to machine precision', presumably this is because of the zeros. The regress function, I understood, manages nan values by excluding them. Should I tell it to treat zeros as nan, or is that too much of an assumption?
% Read in the necessary variables
lat = ncread('file.nc', 'lat');
lon = ncread('file.nc', 'lon');
time = ncread('file.nc', 'time');
TXx = double(ncread('file.nc', 'TXx'));
% Create storage for regression
M = numel(lon);
N = numel(lat);
slope = zeros(M, N);
intercept = zeros(M, N);
T = numel(time);
% Regress each lat/lon location
for i = 1 : M
for j = 1 : N
% Get all time instances of each lat/lon location
y = squeeze(TXx(i, j, :));
% Create regression problem and solve
x = [ones(T, 1) time];
c = regress(y, x);
intercept(i, j) = c(1);
slope(i, j) = c(2);
end
end
  3 个评论
aine gormley
aine gormley 2018-12-6
hi, thanks for your message, sorry -kind of a newbie here - but how would i do a representative sub-sample?
Stephen23
Stephen23 2018-12-6
"but how would i do a representative sub-sample?"
You pick enough of your data so that it shows the behavior that you describe. Start by selecting one single set of x, y, and c arrays where this situation occurs, and upload them here in one .mat file.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Regression 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by