why am i getting zero slope?
2 views (last 30 days)
Show older comments
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 Comments
Stephen23
on 6 Dec 2018
"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.
Answers (0)
See Also
Categories
Find more on Linear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!