2%> This is the base
class for generating objects with methods
3%> and storage components
for computing and storing the
4%> covariance matrix of an input data.<br>
7%> This is convenience
class for easy computation
8%> of covariance and its storage 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 [pm.stats.
Cov](@ref
Cov::
Cov) below.<br>
20%> \JoshuaOsborne, May 21 2024, 4:25 AM, University of Texas at Arlington<br>
21%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
22%> \AmirShahmoradi, July 5 2024, 1:07 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
23classdef
Cov < pm.matlab.Handle
25 properties(Access = public)
29 %> The scalar MATLAB string containing the
30 %> method of computing the covariance matrix.<br>
31 %> It can be either:<br>
33 %> <li> ``"pearson"`` : for computing the Pearson covariance matrix of the input data.
34 %> <li> ``"kendall"`` : for computing the Kendall rank covariance matrix of the input data.
35 %> <li> ``"spearman"`` : for computing the Spearman rank covariance matrix of the input data.
42 %> The MATLAB table of rank ``2`` serving as a
43 %> convenient storage component for the covariance matrix.<br>
44 %> This component is automatically populated at the time of
45 %> constructing an object of class [pm.stats.
Cov](@ref Cov).<br>
46 %> It must be populated manually at all other times.<br>
51 methods(Access = public)
54 %> Return an object of class [pm.stats.
Cov](@ref Cov).<br>
57 %> This is the constructor of the [pm.stats.
Cov](@ref Cov) class.<br>
59 %> \param[in] df : The input MATLAB matrix or table of rank ``2``
60 %> containing the data as ``ncol`` columns of ``nrow``
61 %> observations whose covariance matrix must be computed.<br>
62 %> (**optional**. If missing, the covariance matrix will not be computed.)
64 %> \param[in] method : The input scalar MATLAB string that can be either:<br>
65 %> "pearson" : for computing the Pearson covariance matrix of the input data.<br>
66 %> "spearman" : for computing the Spearman rank covariance matrix of the input data.<br>
67 %> (**optional**, default = ``"pearson"``)
70 %> ``self`` : The output object of class [pm.stats.
Cov](@ref Cov).<br>
75 %> mat = pm.stats.
Cov()
76 %> mat = pm.stats.Cov(df)
77 %> mat = pm.stats.Cov(df, method)
82 %> \include{lineno} example/stats/
Cov/main.m
84 %> \include{lineno} example/stats/
Cov/main.out.m
86 %> \image html example/stats/
Cov/
Cov.unifrnd.png width=700
91 %> \JoshuaOsborne, May 21 2024, 4:29 AM, University of Texas at Arlington<br>
92 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
93 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
94 function self =
Cov(df, method)
99 self.val = self.get(df, self.method);
104 %> Return the covariance matrix of the input data.<br>
107 %> This is a dynamic method of the [pm.stats.Cov](@ref
Cov)
class.<br>
108 %> This method automatically stores any input information
109 %> in the corresponding components of the parent
object.<br>
110 %> However, any components of the parent
object
111 %> corresponding to the output of
this method
112 %> must be set explicitly manually.<br>
114 %> \param[in] df : The input MATLAB matrix or table of rank ``2``
115 %> containing the data as ``ncol`` columns of ``nrow``
116 %> observations whose covariance matrix must be computed.<br>
117 %> \param[in] method : The input scalar MATLAB
string that can be either:<br>
118 %>
"pearson" :
for computing the Pearson covariance matrix of the input data.<br>
119 %>
"spearman" :
for computing the Spearman rank covariance matrix of the input data.<br>
120 %> (**optional**,
default = ``
"pearson"``)
123 %> ``val`` : The output MATLAB ``table`` containing the covariance matrix.<br>
128 %> mat = pm.stats.Cov()
129 %> mat.val = mat.get(df)
130 %> mat.val = mat.get(df, method)
137 %> \JoshuaOsborne, May 21 2024, 4:31 AM, University of Texas at Arlington<br>
138 %> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
139 %> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
140 function val = get(self, df, method)
142 help(
"pm.stats.Cov");
144 +
"The input ``df`` argument is required for computing the covariance matrix." + newline ...
151 self.method = method;
153 data = table2array(df);
157 if strcmpi(self.method, "spearman")
159 data = tiedrank(data);
161 val = NaN(size(data, 2), size(data, 2));
162 warning ( newline ...
163 +
string(me.identifier) + " : " +
string(me.message) + newline ...
164 + "skipping the covariance matrix computation..." + newline ...
171 val = array2table(cov(data));
173 val = NaN(size(data, 2), size(data, 2));
174 warning ( newline ...
175 +
string(me.identifier) + " : " +
string(me.message) + newline ...
176 + "skipping the covariance matrix computation..." + newline ...
182 val.Properties.VariableNames = df.Properties.VariableNames;
184 val.Properties.RowNames = val.Properties.VariableNames;
This is the base class for generating objects with methods and storage components for computing and s...
function get(in self, in df, in method)
Return the covariance matrix of the input data.
function Cov(in df, in method)
Return an object of class pm.stats.Cov.
This is the base class for generating subclass of MATLAB handle superclass whose annoying methods are...