why am i getting zero slope?

3 vues (au cours des 30 derniers jours)
aine gormley
aine gormley le 6 Déc 2018
Commenté : Stephen23 le 6 Déc 2018
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 commentaires
aine gormley
aine gormley le 6 Déc 2018
hi, thanks for your message, sorry -kind of a newbie here - but how would i do a representative sub-sample?
Stephen23
Stephen23 le 6 Déc 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.

Connectez-vous pour commenter.

Réponses (0)

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by