ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_sampleCor::getRho Interface Reference

Generate and return the Spearman rank correlation matrix of the input (weighted) sample of shape (ndim, nsam) or (nsam, ndim) or the Spearman rank correlation coefficient a pair of (weighted) time series x(1:nsam) and y(1:nsam) where ndim is the number of data dimensions (the number of data attributes) and nsam is the number of data points.
More...

Detailed Description

Generate and return the Spearman rank correlation matrix of the input (weighted) sample of shape (ndim, nsam) or (nsam, ndim) or the Spearman rank correlation coefficient a pair of (weighted) time series x(1:nsam) and y(1:nsam) where ndim is the number of data dimensions (the number of data attributes) and nsam is the number of data points.

This generic interface performs one of the following computational tasks:

  1. Compute the Spearman rank correlation coefficient corresponding to an input pair of time series x and y of nsam observations.
  2. Compute the Spearman rank correlation matrix corresponding to an input multivariate sample of nsam observations each with ndim attributes.

See the documentation of the parent module pm_sampleCor for algorithmic details and sample correlation matrix definition.

Parameters
[in]x: The input contiguous vector of shape (nsam) of,
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
  2. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64),
  3. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
  4. type string container css_type,
  5. type string PDT container css_pdt,
or a scalar of,
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary length type parameter,
containing the first attribute x of the observational sample, where nsam is the number of observations in the sample.
(optional. It must be present if and only if the input argument y is present and rho and sample are missing.)
[in]y: The input contiguous vector of shape (nsam) of the same type and kind as the input x, containing the second attribute x of the observational sample, where nsam is the number of observations in the sample.
(optional. It must be present if and only if the input argument x is present and rho and sample are missing.)
[in]sample: The input contiguous array of shape (ndim, nsam) or (nsam, ndim) of,
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
  2. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64),
  3. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
  4. type string container css_type,
  5. type string PDT container css_pdt,
or a scalar of,
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of arbitrary length type parameter,
containing the sample comprised of nsam observations each with ndim attributes.
If sample is a matrix, then the input argument dim dictates the direction along which the correlation matrix rho must be computed (i.e., the direction of individual observations).
(optional. It must be present if and only if the input arguments rho, x, and y are missing.)
[in]dim: The input scalar integer of default kind IK indicating the dimension of sample along which the correlation matrix must be computed.
  1. If dim = 1, the input sample is assumed to have the shape (nsam, ndim).
  2. If dim = 2, the input sample is assumed to have the shape (ndim, nsam).
(optional. It must be present if and only if the input argument sample is present and is of rank 2.)
[in]weight: The input contiguous vector of length nsam,
  1. type integer of default kind IK,
  2. type real of default kind RK,
containing the corresponding weights of individual nsam observations in sample or the pair of vectors x and y.
Note that this default RK kind type parameter requirement on input weight of type real is unlike the other pm_sample* modules of the ParaMonte library.
This requirement is enforced by the default kind type parameter of the output of setRankFractional.
(optional. default = getFilled(1, nsam).)
Returns
rho : The output positive semi-definite scalar or square matrix of shape (1 : ndim, 1 : ndim) of,
  1. type real of default kind RK,
containing the (Spearman rank) correlation coefficient or full correlation matrix corresponding to the input sample or time series x and y, whichever is present.
  1. If x(:) and y(:) are present, then rho shall be a scalara scalar of value \(r_{xy}\),

    \begin{equation} \ms{rho} = \begin{bmatrix} 1 && r_{xy} \\ r_{yx} && 1 ~. \end{bmatrix} \end{equation}

  2. If sample is present, then rho shall be a square matrix of shape [size(sample, 3 - dim), size(sample, 3 - dim)].


Possible calling interfaces

use pm_sampleCor, only: getRho
! XY time series Spearman rank correlation coefficient.
rho = getRho(x(1:nsam), y(1:nsam) ) ! Spearman rank correlation coefficient.
rho = getRho(x(1:nsam), y(1:nsam), weight(1:nsam)) ! Spearman rank correlation coefficient.
! sample Spearman rank correlation matrix.
rho(1:ndim, 1:ndim) = getRho(sample(:,:), dim)
rho(1:ndim, 1:ndim) = getRho(sample(:,:), dim, weight(1:nsam))
Generate and return the Spearman rank correlation matrix of the input (weighted) sample of shape (ndi...
This module contains classes and procedures for computing properties related to the correlation matri...
Warning
All conditions that must hold for the generic interface setRho must equally hold for this generic interface.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
See also
getCor
setCor
getRho
setRho
getCov
setCov
setECDF
getMean
setMean
getShifted
setShifted
getVar
setVar


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK, RK
4 use pm_io, only: display_type
5 use pm_distUnif, only: getUnifRand
6 use pm_distUnif, only: setUnifRand
8 use pm_distCov, only: getCovRand
9 use pm_arrayRange, only: getRange
10 use pm_sampleCor, only: getRho
11 use pm_sampleCor, only: upp
12 use pm_sampleCor, only: low
13 use pm_sampleMean, only: getMean
14 use pm_sampleMean, only: setMean
15 use pm_sampleShift, only: getShifted
16 use pm_arraySpace, only: getLinSpace
17 use pm_arrayResize, only: setResized
18 use pm_arrayFill, only: getFilled
19 use pm_io, only: getFormat
20
21 implicit none
22
23 type(display_type) :: disp
24 integer(IK) :: itry, ntry = 10
25 character(:), allocatable :: format
26 real(RK), allocatable :: rho(:,:), rweight(:)
27 disp = display_type(file = "main.out.F90")
28
29 call disp%skip()
30 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
31 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
32 call disp%show("!Compute the Spearman correlation matrix for a pair of character-sequence time series.")
33 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
34 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
35 call disp%skip()
36
37 block
38 use pm_kind, only: SKG => SK ! All other kinds are also supported.
39 real(RK) :: rho
40 integer(IK) :: nsam
41 character(:,SKG), allocatable :: x, y
42 call disp%show("nsam = 10")
43 nsam = 10
44 call disp%show("x = getUnifRand(repeat('A', nsam), repeat('Z', nsam))")
45 x = getUnifRand(repeat('A', nsam), repeat('Z', nsam))
46 call disp%show("x")
47 call disp%show( x , deliml = SK_'''' )
48 call disp%show("y = getUnifRand(repeat('A', nsam), repeat('Z', nsam))")
49 y = getUnifRand(repeat('A', nsam), repeat('Z', nsam))
50 call disp%show("y")
51 call disp%show( y , deliml = SK_'''' )
52 call disp%show("rho = getRho(x, y)")
53 rho = getRho(x, y)
54 call disp%show("rho")
55 call disp%show( rho )
56 call disp%skip()
57 end block
58
59 call disp%skip()
60 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
61 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
62 call disp%show("!Compute the Spearman correlation matrix for a pair of character-valued time series.")
63 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
64 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
65 call disp%skip()
66
67 block
68 use pm_kind, only: SKG => SK ! All other kinds are also supported.
69 integer(IK) :: ndim, nsam
70 character(2,SKG), allocatable :: sample(:,:)
71 call disp%show("ndim = 2; nsam = 10")
72 ndim = 2; nsam = 10
73 call disp%show("call setResized(sample, [ndim, nsam])")
74 call setResized(sample, [ndim, nsam])
75 call disp%show("call setUnifRand(sample, SKG_'AA', SKG_'ZZ')")
76 call setUnifRand(sample, SKG_'AA', SKG_'ZZ')
77 call disp%show("sample")
78 call disp%show( sample , deliml = SK_'''' )
79 call disp%show("rho = getFilled(0., ndim, ndim)")
80 rho = getFilled(0., ndim, ndim)
81 call disp%show("rho = getRho(sample, dim = 2_IK)")
82 rho = getRho(sample, dim = 2_IK)
83 call disp%show("rho")
84 call disp%show( rho )
85 call disp%skip()
86 call disp%show("Compute the sample correlation along the first dimension.", deliml = SK_'''')
87 call disp%skip()
88 call disp%show("rho = getFilled(0., ndim, ndim)")
89 rho = getFilled(0., ndim, ndim)
90 call disp%show("rho = getRho(transpose(sample), dim = 1_IK)")
91 rho = getRho(transpose(sample), dim = 1_IK)
92 call disp%show("rho")
93 call disp%show( rho )
94 call disp%skip()
95 call disp%show("Compute the full sample correlation for a pair of time series.", deliml = SK_'''')
96 call disp%skip()
97 call disp%show("rho(1,1) = getRho(sample(1,:), sample(2,:))")
98 rho(1,1) = getRho(sample(1,:), sample(2,:))
99 call disp%show("rho(1,1)")
100 call disp%show( rho(1,1) )
101 call disp%skip()
102 end block
103
104 call disp%skip()
105 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
106 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
107 call disp%show("!Compute the Spearman correlation matrix for a pair of integer-valued time series.")
108 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
109 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
110 call disp%skip()
111
112 block
113 use pm_kind, only: IKG => IK ! All other kinds are also supported.
114 integer(IK) :: ndim, nsam
115 integer(IKG), allocatable :: sample(:,:)
116 call disp%show("ndim = 2; nsam = 10")
117 ndim = 2; nsam = 10
118 call disp%show("sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])")
119 sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
120 call disp%show("sample")
121 call disp%show( sample )
122 call disp%show("rho = getFilled(0., ndim, ndim)")
123 rho = getFilled(0., ndim, ndim)
124 call disp%show("rho = getRho(sample, dim = 2_IK)")
125 rho = getRho(sample, dim = 2_IK)
126 call disp%show("rho")
127 call disp%show( rho )
128 call disp%skip()
129 call disp%show("Compute the sample correlation along the first dimension.", deliml = SK_'''')
130 call disp%skip()
131 call disp%show("rho = getFilled(0., ndim, ndim)")
132 rho = getFilled(0., ndim, ndim)
133 call disp%show("rho = getRho(transpose(sample), dim = 1_IK)")
134 rho = getRho(transpose(sample), dim = 1_IK)
135 call disp%show("rho")
136 call disp%show( rho )
137 call disp%skip()
138 call disp%show("Compute the full sample correlation for a pair of time series.", deliml = SK_'''')
139 call disp%skip()
140 call disp%show("rho(1,1) = getRho(sample(1,:), sample(2,:))")
141 rho(1,1) = getRho(sample(1,:), sample(2,:))
142 call disp%show("rho(1,1)")
143 call disp%show( rho(1,1) )
144 call disp%skip()
145 end block
146
147 call disp%skip()
148 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
149 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
150 call disp%show("!Compute the Spearman correlation matrix for a pair of real-valued time series.")
151 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
152 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
153 call disp%skip()
154
155 block
156 use pm_kind, only: RKG => RKS ! All other real types are also supported.
157 integer(IK) :: ndim, nsam
158 real(RKG), allocatable :: sample(:,:)
159 format = getFormat(mold = [0._RKG], ed = SK_"es", signed = .true._LK)
160 call disp%show("ndim = 2; nsam = 10")
161 ndim = 2; nsam = 10
162 call disp%show("sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])")
163 sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
164 call disp%show("sample")
165 call disp%show( sample , format = format )
166 call disp%show("rho = getFilled(0., ndim, ndim)")
167 rho = getFilled(0., ndim, ndim)
168 call disp%show("rho = getRho(sample, dim = 2_IK)")
169 rho = getRho(sample, dim = 2_IK)
170 call disp%show("rho")
171 call disp%show( rho , format = format )
172 call disp%skip()
173 call disp%show("Compute the sample correlation along the first dimension.", deliml = SK_'''')
174 call disp%skip()
175 call disp%show("rho = getFilled(0., ndim, ndim)")
176 rho = getFilled(0., ndim, ndim)
177 call disp%show("rho = getRho(transpose(sample), dim = 1_IK)")
178 rho = getRho(transpose(sample), dim = 1_IK)
179 call disp%show("rho")
180 call disp%show( rho , format = format )
181 call disp%skip()
182 call disp%show("Compute the full sample correlation for a pair of time series.", deliml = SK_'''')
183 call disp%skip()
184 call disp%show("rho(1,1) = getRho(sample(1,:), sample(2,:))")
185 rho(1,1) = getRho(sample(1,:), sample(2,:))
186 call disp%show("rho(1,1)")
187 call disp%show( rho(1,1) , format = format )
188 call disp%skip()
189 end block
190
191 call disp%skip()
192 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
193 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
194 call disp%show("!Compute the Spearman correlation matrix for a weighted pair of time series.")
195 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
196 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
197 call disp%skip()
198
199 block
200 use pm_arrayVerbose, only: getVerbose
201 use pm_kind, only: RKG => RKS ! All other real types are also supported.
202 integer(IK) :: ndim, nsam
203 integer(IK), allocatable :: iweight(:)
204 real(RKG), allocatable :: sample(:,:)
205 format = getFormat(mold = [0._RKG], ed = SK_"es", signed = .true._LK)
206 call disp%show("ndim = 2; nsam = 10")
207 ndim = 2; nsam = 10
208 call disp%show("sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])")
209 sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
210 call disp%show("sample")
211 call disp%show( sample , format = format )
212 call disp%show("iweight = getUnifRand(1, 10, nsam) ! integer-valued weights.")
213 iweight = getUnifRand(1, 10, nsam) ! integer-valued weights.
214 call disp%show("iweight")
215 call disp%show( iweight )
216 call disp%show("rweight = iweight ! or real-valued weights.")
217 rweight = iweight ! or real-valued weights.
218 call disp%show("iweight")
219 call disp%show( iweight )
220
221 call disp%skip()
222 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
223 call disp%show("!Compute the correlation matrix with integer weights.")
224 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
225 call disp%skip()
226
227 call disp%show("rho = getFilled(0., ndim, ndim)")
228 rho = getFilled(0., ndim, ndim)
229 call disp%show("rho = getRho(sample, 2_IK, iweight)")
230 rho = getRho(sample, 2_IK, iweight)
231 call disp%show("rho")
232 call disp%show( rho , format = format )
233 call disp%skip()
234 call disp%show("Compute the sample correlation along the first dimension.", deliml = SK_'''')
235 call disp%skip()
236 call disp%show("rho = getFilled(0., ndim, ndim)")
237 rho = getFilled(0., ndim, ndim)
238 call disp%show("rho = getRho(transpose(sample), 1_IK, iweight)")
239 rho = getRho(transpose(sample), 1_IK, iweight)
240 call disp%show("rho")
241 call disp%show( rho , format = format )
242 call disp%skip()
243 call disp%show("rho = getFilled(0., ndim, ndim)")
244 rho = getFilled(0., ndim, ndim)
245 call disp%skip()
246 call disp%show("Compute the full sample correlation for a pair of time series.", deliml = SK_'''')
247 call disp%skip()
248 call disp%show("rho(1,1) = getRho(sample(1,:), sample(2,:), iweight)")
249 rho(1,1) = getRho(sample(1,:), sample(2,:), iweight)
250 call disp%show("rho(1,1)")
251 call disp%show( rho(1,1) , format = format )
252 call disp%skip()
253
254 call disp%skip()
255 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
256 call disp%show("!Compute the correlation matrix with real weights.")
257 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
258 call disp%skip()
259
260 call disp%show("rho = getFilled(0., ndim, ndim)")
261 rho = getFilled(0., ndim, ndim)
262 call disp%show("rho = getRho(sample, 2_IK, rweight)")
263 rho = getRho(sample, 2_IK, rweight)
264 call disp%show("rho")
265 call disp%show( rho , format = format )
266 call disp%skip()
267 call disp%show("Compute the sample correlation along the first dimension.", deliml = SK_'''')
268 call disp%skip()
269 call disp%show("rho = getFilled(0., ndim, ndim)")
270 rho = getFilled(0., ndim, ndim)
271 call disp%show("rho = getRho(transpose(sample), 1_IK, rweight)")
272 rho = getRho(transpose(sample), 1_IK, rweight)
273 call disp%show("rho")
274 call disp%show( rho , format = format )
275 call disp%skip()
276 call disp%show("rho = getFilled(0., ndim, ndim)")
277 rho = getFilled(0., ndim, ndim)
278 call disp%skip()
279 call disp%show("Compute the full sample correlation for a pair of time series.", deliml = SK_'''')
280 call disp%skip()
281 call disp%show("rho(1,1) = getRho(sample(1,:), sample(2,:), rweight)")
282 rho(1,1) = getRho(sample(1,:), sample(2,:), rweight)
283 call disp%show("rho(1,1)")
284 call disp%show( rho(1,1) , format = format )
285 call disp%skip()
286 end block
287
288end program example
Generate and return an array of the specified rank and shape of arbitrary intrinsic type and kind wit...
Generate minimally-spaced character, integer, real sequences or sequences at fixed intervals of size ...
Allocate or resize (shrink or expand) an input allocatable scalar string or array of rank 1....
Generate and return an output array whose elements are the reversed-order elements of the input array...
Generate count evenly spaced points over the interval [x1, x2] if x1 < x2, or [x2,...
Generate an equally-weighted (verbose or flattened) array of the input weighted array of rank 1 or 2.
Generate and return a random positive-definite (correlation or covariance) matrix using the Gram meth...
Definition: pm_distCov.F90:394
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
Return a uniform random scalar or contiguous array of arbitrary rank of randomly uniformly distribute...
Generate and return a generic or type/kind-specific IO format with the requested specifications that ...
Definition: pm_io.F90:18485
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Generate and return the (weighted) mean of an input sample of nsam observations with ndim = 1 or 2 at...
Return the (weighted) mean of a pair of time series or of an input sample of nsam observations with n...
Generate a sample of shape (nsam), or (ndim, nsam) or (nsam, ndim) that is shifted by the specified i...
This module contains procedures and generic interfaces for convenient allocation and filling of array...
This module contains procedures and generic interfaces for generating ranges of discrete character,...
This module contains procedures and generic interfaces for resizing allocatable arrays of various typ...
This module contains procedures and generic interfaces for reversing the order of elements in arrays ...
This module contains procedures and generic interfaces for generating arrays with linear or logarithm...
This module contains procedures and generic interfaces for flattening (duplicating the elements of) a...
This module contains classes and procedures for generating random matrices distributed on the space o...
Definition: pm_distCov.F90:72
This module contains classes and procedures for computing various statistical quantities related to t...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
This module contains classes and procedures for computing the first moment (i.e., the statistical mea...
This module contains classes and procedures for shifting univariate or multivariate samples by arbitr...
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4!Compute the Spearman correlation matrix for a pair of character-sequence time series.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8nsam = 10
9x = getUnifRand(repeat('A', nsam), repeat('Z', nsam))
10x
11'YIILOULMKY'
12y = getUnifRand(repeat('A', nsam), repeat('Z', nsam))
13y
14'YXJLSBMKMQ'
15rho = getRho(x, y)
16rho
17+0.20552534019485327
18
19
20!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22!Compute the Spearman correlation matrix for a pair of character-valued time series.
23!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25
26ndim = 2; nsam = 10
27call setResized(sample, [ndim, nsam])
28call setUnifRand(sample, SKG_'AA', SKG_'ZZ')
29sample
30'MX', 'SV', 'NK', 'FA', 'DM', 'NL', 'FH', 'FF', 'MF', 'HG'
31'LP', 'DC', 'IC', 'PC', 'HU', 'CQ', 'TR', 'PC', 'TI', 'BF'
32rho = getFilled(0., ndim, ndim)
33rho = getRho(sample, dim = 2_IK)
34rho
35+1.0000000000000000, -0.38905954795524139
36-0.38905954795524139, +1.0000000000000000
37
38'Compute the sample correlation along the first dimension.'
39
40rho = getFilled(0., ndim, ndim)
41rho = getRho(transpose(sample), dim = 1_IK)
42rho
43+1.0000000000000000, -0.38905954795524139
44-0.38905954795524139, +1.0000000000000000
45
46'Compute the full sample correlation for a pair of time series.'
47
48rho(1,1) = getRho(sample(1,:), sample(2,:))
49rho(1,1)
50-0.38905954795524134
51
52
53!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55!Compute the Spearman correlation matrix for a pair of integer-valued time series.
56!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58
59ndim = 2; nsam = 10
60sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
61sample
62+11, +18, +11, +18, +10, +12, +15, +1, +10, +13
63+12, +4, +13, +15, +13, +17, +1, +9, +1, +2
64rho = getFilled(0., ndim, ndim)
65rho = getRho(sample, dim = 2_IK)
66rho
67+1.0000000000000000, +0.27692438781085564E-1
68+0.27692438781085564E-1, +1.0000000000000000
69
70'Compute the sample correlation along the first dimension.'
71
72rho = getFilled(0., ndim, ndim)
73rho = getRho(transpose(sample), dim = 1_IK)
74rho
75+1.0000000000000000, +0.27692438781085564E-1
76+0.27692438781085564E-1, +1.0000000000000000
77
78'Compute the full sample correlation for a pair of time series.'
79
80rho(1,1) = getRho(sample(1,:), sample(2,:))
81rho(1,1)
82+0.27692438781085568E-1
83
84
85!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87!Compute the Spearman correlation matrix for a pair of real-valued time series.
88!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90
91ndim = 2; nsam = 10
92sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
93sample
94+1.800000E+01, +2.000000E+00, +8.000000E+00, +1.200000E+01, +5.000000E+00, +1.200000E+01, +1.700000E+01, +2.000000E+00, +1.100000E+01, +7.000000E+00
95+1.000000E+01, +1.600000E+01, +1.300000E+01, +4.000000E+00, +1.600000E+01, +3.000000E+00, +3.000000E+00, +5.000000E+00, +1.600000E+01, +1.100000E+01
96rho = getFilled(0., ndim, ndim)
97rho = getRho(sample, dim = 2_IK)
98rho
99+1.000000E+00, -5.665879E-01
100-5.665879E-01, +1.000000E+00
101
102'Compute the sample correlation along the first dimension.'
103
104rho = getFilled(0., ndim, ndim)
105rho = getRho(transpose(sample), dim = 1_IK)
106rho
107+1.000000E+00, -5.665879E-01
108-5.665879E-01, +1.000000E+00
109
110'Compute the full sample correlation for a pair of time series.'
111
112rho(1,1) = getRho(sample(1,:), sample(2,:))
113rho(1,1)
114-5.665879E-01
115
116
117!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119!Compute the Spearman correlation matrix for a weighted pair of time series.
120!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122
123ndim = 2; nsam = 10
124sample = reshape(getUnifRand(1, 20, ndim * nsam), shape = [ndim, nsam], order = [2, 1])
125sample
126+1.600000E+01, +2.000000E+00, +1.000000E+01, +1.700000E+01, +1.300000E+01, +1.300000E+01, +7.000000E+00, +1.000000E+01, +1.800000E+01, +1.000000E+00
127+1.300000E+01, +1.300000E+01, +1.900000E+01, +1.100000E+01, +1.300000E+01, +1.500000E+01, +5.000000E+00, +1.200000E+01, +1.200000E+01, +1.700000E+01
128iweight = getUnifRand(1, 10, nsam) ! integer-valued weights.
129iweight
130+8, +7, +5, +10, +6, +8, +8, +5, +9, +2
131rweight = iweight ! or real-valued weights.
132iweight
133+8, +7, +5, +10, +6, +8, +8, +5, +9, +2
134
135!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136!Compute the correlation matrix with integer weights.
137!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138
139rho = getFilled(0., ndim, ndim)
140rho = getRho(sample, 2_IK, iweight)
141rho
142+1.000000E+00, -2.158326E-01
143-2.158326E-01, +1.000000E+00
144
145'Compute the sample correlation along the first dimension.'
146
147rho = getFilled(0., ndim, ndim)
148rho = getRho(transpose(sample), 1_IK, iweight)
149rho
150+1.000000E+00, -2.158326E-01
151-2.158326E-01, +1.000000E+00
152
153rho = getFilled(0., ndim, ndim)
154
155'Compute the full sample correlation for a pair of time series.'
156
157rho(1,1) = getRho(sample(1,:), sample(2,:), iweight)
158rho(1,1)
159-2.158326E-01
160
161
162!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163!Compute the correlation matrix with real weights.
164!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165
166rho = getFilled(0., ndim, ndim)
167rho = getRho(sample, 2_IK, rweight)
168rho
169+1.000000E+00, -2.158326E-01
170-2.158326E-01, +1.000000E+00
171
172'Compute the sample correlation along the first dimension.'
173
174rho = getFilled(0., ndim, ndim)
175rho = getRho(transpose(sample), 1_IK, rweight)
176rho
177+1.000000E+00, -2.158326E-01
178-2.158326E-01, +1.000000E+00
179
180rho = getFilled(0., ndim, ndim)
181
182'Compute the full sample correlation for a pair of time series.'
183
184rho(1,1) = getRho(sample(1,:), sample(2,:), rweight)
185rho(1,1)
186-2.158326E-01
187
188
Test:
test_pm_sampleCor


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Fatemeh Bagheri, Monday 02:15 AM, September 27, 2021, Dallas, TX
Amir Shahmoradi, Monday March 6, 2017, 3:22 pm, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin.

Definition at line 7643 of file pm_sampleCor.F90.


The documentation for this interface was generated from the following file: