How to ignore columns which have only NaNs and move onto the next column for the mutli regression?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I am trying to run a multi regression with 6 variables. Some of the variables data have columns which consist only out of NaNs. (all-NaN columns are not always the same for all variables)
How could I ignore columns which consist of all NaNs and move to the next column if this is a case for any of the variables?
Please see below my code for the regression:
numRegressors = 6;
numTickers = size(y,2);
numDays = size (y,1);
mat_betas=nan(numRegressors+1,numTickers); %beta coefficients
mat_tstats=nan(numRegressors+1,numTickers); %t-stats
vec_rsqrds=nan(1,numTickers); %r-squares
mat_pval=nan(numRegressors+1,numTickers); %p-values
whichstats = {'beta','rsquare','tstat'};
for column = 1:size(y,2);
All_Factors = [a(:,column) b(:,column) c(:,column) d(:,column) e(:,column) f(:,column)];
all_stats = regstats(y(:,column),All_Factors,'linear',whichstats);
mat_betas(1:numRegressors+1,column)=all_stats.beta;
mat_tstats(:,column)=all_stats.tstat.t;
vec_rsqrds(:,column)=all_stats.rsquare;
mat_pval(:,column)=all_stats.tstat.pval;
end
Thank you in advance.
0 Commenti
Risposta accettata
KSSV
il 27 Ott 2017
You can check whether a number is nan or not using isnan. Read about it.
You can remove the NaN's from the column and then proceed.
% some random data
data = rand(100,1) ;
data(randperm(100,30)) = NaN ; % introduced NaN's
%%remove NaN's
data(isnan(data)) = [] ;
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Linear Regression in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!