2%> This is the base
class for generating objects with methods
3%> and storage components
for computing, storing, and visualizing
4%> the correlation matrix of an input data.<br>
7%> This is convenience
class for easy correlation computation
8%> and its storage and visualization all in one place.<br>
9%> The primary advantage of
this class over the MATLAB
10%> intrinsic functions is in the ability of
this class
11%> to compute the result
for input dataframe table and
12%>
return the results always in MATLAB ``table`` format.<br>
15%> See the documentation of the
class constructor below.<br>
18%> See also the documentation of the superclass [pm.stats.Cov](@ref
Cov).<br>
23%> \JoshuaOsborne, May 21 2024, 4:16 AM, University of Texas at Arlington<br>
24%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
25%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
26classdef
Cor < pm.stats.Cov
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 properties(Access =
public)
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 methods(Access = public)
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %> Return an
object of class [pm.stats.
Cor](@ref
Cor).<br>
43 %> This is the constructor of the [pm.stats.
Cor](@ref
Cor) class.<br>
45 %> \param[in] dfref : The input MATLAB matrix or table of rank ``2``
46 %> containing the data as ``ncol`` columns of ``nrow``
47 %> observations whose correlation matrix must be computed.<br>
48 %> Ideally, the user would want to pass a reference
49 %> to a dataframe (e.g., as a function handle ``@()df``)
50 %> so that the data remains dynamically up-to-date.<br>
51 %> (**optional**. If missing or empty, the correlation matrix will not be computed.)
52 %> \param[in] method : The input scalar MATLAB
string that can be either:<br>
54 %> <li> ``"pearson"`` : for computing the Pearson correlation matrix of the input data.<br>
55 %> <li> ``"kendall"`` : for computing the Kendall correlation matrix of the input data.<br>
56 %> <li> ``"spearman"`` : for computing the Spearman rank correlation matrix of the input data.<br>
58 %> (**optional**, default = ``"pearson"``)
61 %> ``self`` : The output
object of class [pm.stats.
Cor](@ref
Cor).<br>
66 %> mat = pm.stats.
Cor([])
67 %> mat = pm.stats.Cor([], [])
68 %> mat = pm.stats.Cor([], method)
70 %> mat = pm.stats.Cor(dfref)
71 %> mat = pm.stats.Cor(dfref, [])
72 %> mat = pm.stats.Cor(dfref, method)
77 %> \include{lineno} example/stats/
Cor/main.m
79 %> \include{lineno} example/stats/
Cor/main.out.m
81 %> \image html example/stats/
Cor/
Cor.unifrnd.png width=700
86 %> \JoshuaOsborne, May 21 2024, 4:22 AM, University of Texas at Arlington<br>
87 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
88 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
89 function self =
Cor(dfref, method)
96 self.val = self.
get(dfref, self.method);
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 %> Return the correlation matrix of the input data.<br>
109 %> This is a dynamic method of the ``
Cor``
class.<br>
110 %> This method automatically stores any input information
111 %> in the corresponding components of the parent
object.<br>
112 %> However, any components of the parent
object
113 %> corresponding to the output of
this method
114 %> must be set explicitly manually.<br>
116 %> \param[inout] self : The **implicitly-passed** input argument representing the parent
object of the method.<br>
117 %> \param[in] dfref : The input (reference of function handle returning a) MATLAB matrix or table of rank ``2``
118 %> containing the ``ncol`` columns of ``nrow`` data whose correlation matrix must be computed.<br>
119 %> Ideally, the user would want to pass a reference to a dataframe (e.g., as a function handle ``@()df``)
120 %> so that the data remains dynamically up-to-date.<br>
121 %> (**optional**. If missing, the correlation matrix will not be computed.)
122 %> \param[in] method : The input scalar MATLAB
string that can be either:<br>
124 %> <li> ``
"pearson"`` :
for computing the Pearson correlation matrix of the input data.<br>
125 %> <li> ``
"kendall"`` :
for computing the kendall rank correlation matrix of the input data.<br>
126 %> <li> ``
"spearman"`` :
for computing the Spearman rank correlation matrix of the input data.<br>
128 %> (**optional**,
default = ``
"pearson"``)
131 %> ``val`` : The output MATLAB ``table`` containing the correlation matrix.<br>
136 %> mat = pm.stats.
Cor(dfref, method)
138 %> mat.val = mat.get()
139 %> mat.val = mat.get([])
140 %> mat.val = mat.get([], [])
141 %> mat.val = mat.get([], method)
143 %> mat.val = mat.get(dfref)
144 %> mat.val = mat.get(dfref, [])
145 %> mat.val = mat.get(dfref, method)
150 %> See the documentation of the
class constructor
151 %> [pm.stats.Cor](@ref
Cor::Cor)
for example usage.<br>
156 %> \JoshuaOsborne, May 21 2024, 4:24 AM, University of Texas at Arlington<br>
157 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
158 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
159 function val = get(self, dfref, method)
169 self.method = method;
171 self.dfref = pm.container.DataFrame(dfref);
174 dfcopy = self.dfref.copy();
179 help(
"pm.stats.Cov");
181 +
"A non-mepty ``dfref`` attribute or input argument is required for computing the covariance matrix." + newline ...
187 %%%% Compute the correlation matrix.
191 val = array2table(corr(data,
"type", self.method));
193 val = NaN(size(data, 2), size(data, 2));
194 warning ( newline ...
195 +
string(me.identifier) +
" : " +
string(me.message) + newline ...
196 +
"skipping the correlation matrix computation..." + newline ...
202 %%%% Set the matrix column and row names.
205 if isa(dfcopy,
"table")
206 val.Properties.VariableNames = dfcopy.Properties.VariableNames;
208 val.Properties.RowNames = val.Properties.VariableNames;
212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 methods(Access = public, Hidden)
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 %> Set up the visualization tools of the correlation matrix.<br>
226 %> This is a dynamic ``Hidden`` method of the [pm.stats.
Cor](@ref
Cor) class.<br>
227 %> This method is inaccessible to the end users of the ParaMonte MATLAB library.<br>
229 %> \param[inout] self : The **implicitly-passed** input argument representing the parent
object of the method.<br>
230 %> \param[in] val : The input (reference of function handle returning a) MATLAB matrix or table of rank ``2``
231 %> containing the computed correlation matrix to be visualized.<br>
232 %> Ideally, the user would want to pass a reference to a dataframe (e.g., as a function handle ``@()df``)
233 %> so that the data remains dynamically up-to-date.<br>
234 %> (**optional**. If missing, the contents of the corresponding ``var`` attribute of the parent
object will be used.)
236 %> \interface{setvis}
239 %> mat = pm.stats.Cor(dfref, method)
240 %> mat.setvis(); % This method is automatically called within the
object constructor.
247 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
248 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
249 function setvis(self, val)
255 setvis@pm.stats.Cov(self);
256 self.vis.heatmap.subplot.title.titletext =
"Correlation Matrix";
260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This is the base class for generating objects with methods and storage components for computing,...
function get(in self, in dfref, in method)
Return the correlation matrix of the input data.
function Cor(in dfref, in method)
Return an object of class pm.stats.Cor.
function setvis(in self, in val)
Set up the visualization tools of the correlation matrix.
This is the base class for generating objects with methods and storage components for computing and s...