Home > utils > report_corr_table.m

report_corr_table

PURPOSE ^

Prints a correlation table

SYNOPSIS ^

function report_corr_table(corr_st, params)

DESCRIPTION ^

 Prints a correlation table
 INPUT:
 corr_st.r - matrix containing the correlations
 corr_st.p - matrix containing the corresponding p values
 corr_st.N - scalar indicating number of observations

 params.varLabels - cell array of variable names
 params.precision - number of significant digits to print
 params.paths.analyses - path to where the file should be saved
 params.fname - filename to associate with the file
 params.write2file - saved to file if true; otherwise reported to screen
 params.delim - string specifying the delimiter to use when writing the
 file

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function report_corr_table(corr_st, params)
0002 % Prints a correlation table
0003 % INPUT:
0004 % corr_st.r - matrix containing the correlations
0005 % corr_st.p - matrix containing the corresponding p values
0006 % corr_st.N - scalar indicating number of observations
0007 %
0008 % params.varLabels - cell array of variable names
0009 % params.precision - number of significant digits to print
0010 % params.paths.analyses - path to where the file should be saved
0011 % params.fname - filename to associate with the file
0012 % params.write2file - saved to file if true; otherwise reported to screen
0013 % params.delim - string specifying the delimiter to use when writing the
0014 % file
0015 
0016 % 12Aug2014 Petr Janata
0017 
0018 % Set any missing variables
0019 if ~isfield(params,'delim')
0020   delim = '\t';
0021 else
0022   delim = params.delim;
0023 end
0024 
0025 if ~isfield(params,'precision')
0026   precision = 2;
0027 end
0028 
0029 if ~isfield(params,'varLabels')
0030   varLabels = {};
0031 else
0032   varLabels = params.varLabels;
0033 end
0034 
0035 % Perform sanity checks
0036 nvars = size(corr_st.r,1);
0037 nlabels = length(varLabels);
0038 if nlabels ~= nvars
0039   error('Mismatch in number of variables (%d) and variable labels (%d)', nvars, nlabels)
0040 end
0041 
0042 % Get the file identifier
0043 if strcmp(delim,',')
0044   fext = '.csv';
0045 else
0046   fext = '.txt';
0047 end
0048 params.fname = fullfile(params.paths.analyses,[params.fstub fext]);
0049 fid = ensemble_init_fid(params);
0050 
0051 % Write the header line
0052 fprintf(fid,delim);
0053 for ivar = 1:nvars
0054   fprintf(fid,varLabels{ivar});
0055   if ivar < nvars
0056     fprintf(fid,delim);
0057   else
0058     fprintf(fid,'\n');
0059   end
0060 end
0061 
0062 % Write the data
0063 fmt_str = sprintf('%%.%df%%s', precision);
0064 
0065 for ivar = 1:nvars
0066   fprintf(fid,sprintf('%%s%s',delim),varLabels{ivar});
0067   for jvar = 1:nvars
0068     fprintf(fid,fmt_str,corr_st.r(ivar,jvar),prob2str(corr_st.p(ivar,jvar),0.05,'*',3,false));
0069     if jvar < nvars
0070       fprintf(fid,delim);
0071     else
0072       fprintf(fid,'\n');
0073     end
0074   end % for jvar
0075 end % for ivar

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003