Transferring Linear Models to excel/csv
Show older comments
I am running multiple linear regressions with one X variable and 49 Y's. So I now have 49 different linear models (which I put into an array thoguh that isn't of much help in visually consolidating them). I want to put all the linear models into an xls/csv sheet, organized by variable, but the overly complicated structure of the Linear Model object has made it impossible for me to figure out a way to do so. My final resort may be manually building a table with each variable vs lm parameter but that method comes with its own snags, and there has got to be a more efficient way to do this. I also used diary but it's a very poor substitute (as the file in txt and the formatting is illegible). Help!
diary on
for i=2:50
XY = DataFinal{:,[1,i]};
%removing rows with NaN values in Y variable all columns have some missing data
XY(any(isnan(XY), 2), :) = [];
%creating linear model
Fit = fitlm(XY(:,1),XY(:,2))
disp(DataFinal.Properties.VariableNames{i})
disp(Fit)
%Adding significant pValue Y-variables to array pSig
if Fit.Coefficients.pValue(2) <= 0.05
VN=DataFinal.Properties.VariableNames{i};
pVal=Fit.Coefficients.pValue(2);
pSig=[pSig;VN];
pValSig=[pValSig;pVal];
end
%Adding fit model to array
Fitc{1,i-1} = Fit;
end
Sigs = [pSig,pValSig];
TSigs = array2table([pSig,pValSig], 'VariableNames',{'Significant Variables', 'p Values'})
diary off
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics 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!