why am i getting zero slope?

조회 수: 5 (최근 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