X is rank deficient to within machine precision. Linear regression of mean

2 次查看(过去 30 天)
Hello, so I am writing code to do a linear regression on 2 variables - each variable exists on 5 different nc files, so I have to draw the data from them first.
The code is below. It is generating sensible figures and statistics. However, I keep getting the amber warning:
"Warning: X is rank deficient to within machine precision"
>In regress (line 84)
>In mean_ctl2 (line 54)
Is this perhaps because the code is generating the mean slopes (rather than the slope of the mean variable)?
% Loop through the five files - 001 to 005, read and save what is needed
num_files = 5;
for i = 1 : num_files
lat = ncread(sprintf('f.io192.00%d_atm_h1_yearmean_selname.nc', i), 'lat');
lon = ncread(sprintf('f.io192.00%d_atm_h1_yearmean_selname.nc', i), 'lon');
time = ncread(sprintf('f.io192.00%d_atm_h1_yearmean_selname.nc', i), 'time');
TSA = ncread(sprintf('f.io192.00%d_lnd_h1_yearmean_selname.nc', i), 'TSA');
TXx = ncread(sprintf('f.io192.00%d_atm_h1_yearmean_selname.nc', i), 'TXx');
TXxs = cat(4, TXxs, TXx);
TSAs = cat(4, TSAs, TSA);
end
% Create storage for regression
% Number of lat and lon and times must be the same across all 5 files
M = numel(lon);
N = numel(lat);
slope_TXx = zeros(M, N, num_files);
intercept_TXx = zeros(M, N, num_files);
slope_TSA = zeros(M, N, num_files);
intercept_TSA = zeros(M, N, num_files);
T = numel(time);
% Regress each lat/lon location
for i = 1 : M
for j = 1 : N
% Take each file
for k = 1 : num_files
% Get all time instances of each lat/lon location for TXx
y = squeeze(TXxs(i, j, :, k));
% Create regression problem and solve
x = [ones(T, 1) time];
%c = x \ y;
c = regress(y, x);
intercept_TXx(i, j, k) = c(1);
slope_TXx(i, j, k) = c(2);
% Repeat for TSA
y = squeeze(TSAs(i, j, :, k));
% Create regression problem and solve
%x = [ones(T, 1) time];
%c = x \ y;
c = regress(y, x);
intercept_TSA(i, j, k) = c(1);
slope_TSA(i, j, k) = c(2);
end
end
end
% Find the mean of each file
mean_slope_TXx = mean(slope_TXx, 3);
mean_slope_TSA = mean(slope_TSA, 3);
mean_intercept_TXx = mean(intercept_TXx, 3);
mean_intercept_TSA = mean(intercept_TSA, 3);

回答(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