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

Return the variance of an input (weighted) sample of type complex or real of shape (nsam) or (ndim, nsam) or (nsam, ndim) where ndim is the number of data dimensions (the number of data attributes) and nsam is the number of data points.
More...

Detailed Description

Return the variance of an input (weighted) sample of type complex or real of shape (nsam) or (ndim, nsam) or (nsam, ndim) where ndim is the number of data dimensions (the number of data attributes) and nsam is the number of data points.

See the documentation of the parent module pm_sampleVar for algorithmic details and variance definitions.

Parameters
[out]var: The output object of rank rank(sample) - 1 of type real of the same kind as the input sample representing its variance:
  1. If sample is a vector, the output var must be a scalar.
  2. If sample is a matrix, the output var must be a vector of size ndim = size(sample, 3 - dim).
[in]mean: The input scalar or contiguous vector of shape (ndim) of the same type and kind as the input sample containing the sample mean.
  1. If the input sample is a 1D array, then mean must be a scalar.
  2. If the input sample is a 2D array, then mean must be a vector of size ndim = size(sample, 3 - dim) (i.e., computed along the specified input dimension dim).
(optional. default = 0. or getFilled(0., ndim) depending on the rank of the input sample and value of dim.)
[in]sample: The input contiguous array of shape (nsam), (ndim, nsam), or (nsam, ndim) of,
  1. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128),
  2. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
containing the sample comprised of nsam observations each with ndim attributes.
If sample is a matrix, then the direction along which variance is computed is dictated by the input argument dim.
[in]dim: The input scalar integer of default kind IK representing the dimension (1 or 2) of the input sample along which the mean must be computed.
  1. If dim = 1, the input sample of rank 2 is assumed to have the shape (nsam, ndim).
  2. If dim = 2, the input sample of rank 2 is assumed to have the shape (ndim, nsam).
The input dim must always be 1 or missing for an input sample of rank 1.
(optional. If missing, the variance of the whole input sample is computed.)
[in]weight: The input contiguous vector of length nsam of
  1. type integer of default kind IK, or
  2. type real of the same kind as the input sample,
containing the corresponding weights of individual nsam observations in sample.
(optional. default = getFilled(1, size(sample, dim)) if dim is present, or getFilled(1, size(sample)) if dim is missing.)
[in]weisum: The input scalar of the same type and kind as the input weight containing sum(weight).
This quantity is also a byproduct of computing the mean of a sample and is automatically returned by setMean().
(optional. It must be present if and only if the input argument weight is also present.)
[in]correction: The input scalar object that can be the following:
  1. The constant fweight or an object of type fweight implying a bias correction based on the assumption of frequency weights for the sample observations, even if the weight argument is missing.
    This is the most popular type of correction, also known as the Bessel correction.
  2. The constant rweight or an object of type rweight_type implying a bias correction based on the assumption of reliability weights for the sample observations.
(optional. If missing, no bias-correction will be applied to the output var.)


Possible calling interfaces

use pm_sampleVar, only: setVar
! 1D sample unweighted
call setVar(var, sample(1 : nsam))
call setVar(var, mean, sample(1 : nsam))
call setVar(var, sample(1 : nsam), dim)
call setVar(var, mean, sample(1 : nsam), dim)
! 1D sample weighted
call setVar(var, sample(1 : nsam), weight(1 : nsam))
call setVar(var, mean, sample(1 : nsam), weight(1 : nsam), weisum)
call setVar(var, sample(1 : nsam), dim, weight(1 : nsam))
call setVar(var, mean, sample(1 : nsam), dim, weight(1 : nsam), weisum)
! 2D sample unweighted
call setVar(var(1 : size(sample, 3 - dim)), sample(:,:), dim)
call setVar(var(1 : size(sample, 3 - dim)), mean(1 : size(sample, 3 - dim)), sample(:,:), dim)
! 2D sample weighted
call setVar(var(1 : size(sample, 3 - dim)), sample(:,:), dim, weight(1 : size(sample, dim)))
call setVar(var(1 : size(sample, 3 - dim)), mean(1 : size(sample, 3 - dim)), sample(:,:), dim, weight(1 : size(sample, dim)), weisum)
! 2D whole sample unweighted
call setVar(var, sample(:,:))
call setVar(var, mean, sample(:,:))
! 2D whole sample weighted
call setVar(var, sample(:,:), weight(1 : size(sample)))
call setVar(var, mean, sample(:,:), dim, weight(1 : size(sample)), weisum)
Return the variance of an input (weighted) sample of type complex or real of shape (nsam) or (ndim,...
This module contains classes and procedures for computing the properties related to the covariance ma...
Warning
The condition 0 < sum(weight) must hold for the corresponding input arguments.
The condition all(0. <= weight) must hold for the corresponding input arguments.
The condition 1 < size(sample, dim) must hold for the corresponding input arguments.
The condition 0 < size(sample, 3 - dim) must hold for the corresponding input arguments.
The condition 1 <= dim .and. dim <= rank(sample) must hold for the corresponding input arguments.
The condition size(sample, 3 - dim) == size(var) must hold for the corresponding input arguments.
The condition size(sample, 3 - dim) == size(mean) must hold for the corresponding input arguments.
The condition size(sample, dim) == size(weight) must hold for the corresponding input arguments.
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.
Note
Note the effects of bias-correction in computing the variance become noticeable only for very sample sample sizes (i.e., when nsam is small).
For a one-dimensional sample, one can also use the concise Fortran syntax to achieve the same goal as with the interface var = setVar(sample(:), mean, correction) with integer weight:
mean = sum(sample) / size(sample)
var = sum( (sample-mean)**2 ) / (size(sample) - 1)
But the above concise version will be likely slightly slower as it potentially involves more loops.
For a two or higher-dimensional sample, if the variance is to be computed for the entire sample (as opposed to computing it along a particular dimension), simply pass reshape(sample, shape = size(sample)) to the appropriate setVar interface.
Alternatively, a 1D pointer of the same size as the multidimensional sample can be passed to the procedure.
See also
getVar
setVar
getMean
setMean
setVarMean
getShifted
setShifted


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK, RK
4 use pm_kind, only: TKG => RKS ! All other real types are also supported.
5 use pm_io, only: display_type
6 use pm_sampleVar, only: setVar
8 use pm_sampleCov, only: fweight, rweight
10 use pm_arrayResize, only: setResized
11 use pm_distUnif, only: getUnifRand
12 use pm_sampleMean, only: getMean
13 use pm_sampleMean, only: setMean
14
15 implicit none
16
17 integer(IK) :: dim
18 type(display_type) :: disp
19 disp = display_type(file = "main.out.F90")
20
21 call disp%skip()
22 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
23 call disp%show("!Compute the variance of a 1-D sample.")
24 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
25 call disp%skip()
26
27 block
28 real(TKG) :: var, mean
29 real(TKG), allocatable :: sample(:)
30 call disp%show("sample = getLinSpace(1._TKG, 9._TKG, 5_IK)")
31 sample = getLinSpace(1._TKG, 9._TKG, 5_IK)
32 call disp%show("sample")
33 call disp%show( sample )
34 call disp%show("mean = getMean(sample)")
35 mean = getMean(sample)
36 call disp%show("mean")
37 call disp%show( mean )
38 call disp%show("call setVar(var, mean, sample)")
39 call setVar(var, mean, sample)
40 call disp%show("var")
41 call disp%show( var )
42 call disp%show("call setVar(var, sample - mean)")
43 call setVar(var, sample - mean)
44 call disp%show("var")
45 call disp%show( var )
46 call disp%show("call setVar(var, mean, sample, dim = 1_IK)")
47 call setVar(var, mean, sample, dim = 1_IK)
48 call disp%show("var")
49 call disp%show( var )
50 call disp%show("call setVar(var, sample - mean, dim = 1_IK)")
51 call setVar(var, sample - mean, dim = 1_IK)
52 call disp%show("var")
53 call disp%show( var )
54 call disp%skip()
55 end block
56
57 block
58 real(TKG) :: var
59 complex(TKG) :: mean
60 complex(TKG), allocatable :: sample(:)
61 call disp%show("sample = cmplx(getLinSpace(1., 9., 5_IK), -getLinSpace(1., 9., 5_IK), TKG)")
62 sample = cmplx(getLinSpace(1., 9., 5_IK), -getLinSpace(1., 9., 5_IK), TKG)
63 call disp%show("sample")
64 call disp%show( sample )
65 call disp%show("mean = getMean(sample)")
66 mean = getMean(sample)
67 call disp%show("mean")
68 call disp%show( mean )
69 call disp%show("call setVar(var, mean, sample)")
70 call setVar(var, mean, sample)
71 call disp%show("var")
72 call disp%show( var )
73 call disp%show("call setVar(var, sample - mean)")
74 call setVar(var, sample - mean)
75 call disp%show("var")
76 call disp%show( var )
77 call disp%show("call setVar(var, mean, sample, dim = 1_IK)")
78 call setVar(var, mean, sample, dim = 1_IK)
79 call disp%show("var")
80 call disp%show( var )
81 call disp%show("call setVar(var, sample - mean, dim = 1_IK)")
82 call setVar(var, sample - mean, dim = 1_IK)
83 call disp%show("var")
84 call disp%show( var )
85 call disp%skip()
86 end block
87
88 call disp%skip()
89 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
90 call disp%show("!Compute the variance of a 1-D weighted sample.")
91 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
92 call disp%skip()
93
94 block
95 real(TKG) :: var, weisum
96 real(TKG), allocatable :: weight(:)
97 real(TKG), allocatable :: sample(:)
98 real(TKG) :: mean
99 call disp%show("sample = getLinSpace(1._TKG, 9._TKG, 5_IK)")
100 sample = getLinSpace(1._TKG, 9._TKG, 5_IK)
101 call disp%show("sample")
102 call disp%show( sample )
103 call disp%show("weight = getLinSpace(1._TKG, 9._TKG, size(sample, kind = IK))")
104 weight = getLinSpace(1._TKG, 9._TKG, size(sample, kind = IK))
105 call disp%show("weight")
106 call disp%show( weight )
107 call disp%show("call setMean(mean, sample, weight, weisum)")
108 call setMean(mean, sample, weight, weisum)
109 call disp%show("mean")
110 call disp%show( mean )
111 call disp%show("call setVar(var, mean, sample, weight, weisum)")
112 call setVar(var, mean, sample, weight, weisum)
113 call disp%show("var")
114 call disp%show( var )
115 call disp%show("call setVar(var, sample - mean, weight, weisum)")
116 call setVar(var, sample - mean, weight, weisum)
117 call disp%show("var")
118 call disp%show( var )
119 call disp%show("call setVar(var, mean, sample, 1_IK, weight, weisum)")
120 call setVar(var, mean, sample, 1_IK, weight, weisum)
121 call disp%show("var")
122 call disp%show( var )
123 call disp%show("call setVar(var, sample - mean, 1_IK, weight, weisum)")
124 call setVar(var, sample - mean, 1_IK, weight, weisum)
125 call disp%show("var")
126 call disp%show( var )
127 call disp%skip()
128 end block
129
130 block
131 real(TKG) :: var, weisum
132 real(TKG), allocatable :: weight(:)
133 complex(TKG), allocatable :: sample(:)
134 complex(TKG) :: mean
135 call disp%show("sample = cmplx(getLinSpace(1., 9., 5_IK), -getLinSpace(1., 9., 5_IK), TKG)")
136 sample = cmplx(getLinSpace(1., 9., 5_IK), -getLinSpace(1., 9., 5_IK), TKG)
137 call disp%show("sample")
138 call disp%show( sample )
139 call disp%show("weight = getLinSpace(1._TKG, 9._TKG, size(sample, kind = IK))")
140 weight = getLinSpace(1._TKG, 9._TKG, size(sample, kind = IK))
141 call disp%show("weight")
142 call disp%show( weight )
143 call disp%show("call setMean(mean, sample, weight, weisum)")
144 call setMean(mean, sample, weight, weisum)
145 call disp%show("mean")
146 call disp%show( mean )
147 call disp%show("call setVar(var, mean, sample, weight, weisum)")
148 call setVar(var, mean, sample, weight, weisum)
149 call disp%show("var")
150 call disp%show( var )
151 call disp%show("call setVar(var, sample - mean, weight, weisum)")
152 call setVar(var, sample - mean, weight, weisum)
153 call disp%show("var")
154 call disp%show( var )
155 call disp%show("call setVar(var, mean, sample, 1_IK, weight, weisum)")
156 call setVar(var, mean, sample, 1_IK, weight, weisum)
157 call disp%show("var")
158 call disp%show( var )
159 call disp%show("call setVar(var, sample - mean, 1_IK, weight, weisum)")
160 call setVar(var, sample - mean, 1_IK, weight, weisum)
161 call disp%show("var")
162 call disp%show( var )
163 call disp%skip()
164 end block
165
166 call disp%skip()
167 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
168 call disp%show("!Compute the variance of a 2-D array.")
169 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
170 call disp%skip()
171
172 block
173 real(TKG), allocatable :: var(:), mean(:), sample(:,:)
174 call disp%skip()
175 call disp%show("sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)")
176 sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
177 call disp%show("sample")
178 call disp%show( sample )
179 call disp%show("mean = [getMean(sample)]")
180 mean = [getMean(sample)]
181 call disp%show("mean")
182 call disp%show( mean )
183 call disp%show("call setResized(var, size(mean, 1, IK))")
184 call setResized(var, size(mean, 1, IK))
185 call disp%show("call setVar(var(1), mean(1), sample)")
186 call setVar(var(1), mean(1), sample)
187 call disp%show("var")
188 call disp%show( var )
189 call disp%show("call setVar(var(1), sample - mean(1))")
190 call setVar(var(1), sample - mean(1))
191 call disp%show("var")
192 call disp%show( var )
193 call disp%skip()
194 do dim = 1, 2
195 call disp%show("dim ! The observations axis.")
196 call disp%show( dim )
197 call disp%show("sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)")
198 sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
199 call disp%show("sample")
200 call disp%show( sample )
201 call disp%show("mean = getMean(sample, dim)")
202 mean = getMean(sample, dim)
203 call disp%show("mean")
204 call disp%show( mean )
205 call disp%show("call setResized(var, size(mean, 1, IK))")
206 call setResized(var, size(mean, 1, IK))
207 call disp%show("call setVar(var, mean, sample, dim)")
208 call setVar(var, mean, sample, dim)
209 call disp%show("var")
210 call disp%show( var )
211 call disp%show("call setVar(var, getShifted(sample, dim, -mean), dim)")
212 call setVar(var, getShifted(sample, dim, -mean), dim)
213 call disp%show("var")
214 call disp%show( var )
215 call disp%skip()
216 end do
217 end block
218
219 block
220 real(TKG), allocatable :: var(:)
221 complex(TKG), allocatable :: mean(:), sample(:,:)
222 call disp%skip()
223 call disp%show("sample = cmplx(getUnifRand(1., 9., 4_IK, 5_IK), -getUnifRand(1., 9., 4_IK, 5_IK), TKG)")
224 sample = cmplx(getUnifRand(1., 9., 4_IK, 5_IK), -getUnifRand(1., 9., 4_IK, 5_IK), TKG)
225 call disp%show("sample")
226 call disp%show( sample )
227 call disp%show("mean = [getMean(sample)]")
228 mean = [getMean(sample)]
229 call disp%show("mean")
230 call disp%show( mean )
231 call disp%show("call setResized(var, size(mean, 1, IK))")
232 call setResized(var, size(mean, 1, IK))
233 call disp%show("call setVar(var(1), mean(1), sample)")
234 call setVar(var(1), mean(1), sample)
235 call disp%show("var")
236 call disp%show( var )
237 call disp%show("call setVar(var(1), sample - mean(1))")
238 call setVar(var(1), sample - mean(1))
239 call disp%show("var")
240 call disp%show( var )
241 call disp%skip()
242 do dim = 1, 2
243 call disp%show("dim ! The observations axis.")
244 call disp%show( dim )
245 call disp%show("sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)")
246 sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
247 call disp%show("sample")
248 call disp%show( sample )
249 call disp%show("mean = getMean(sample, dim)")
250 mean = getMean(sample, dim)
251 call disp%show("mean")
252 call disp%show( mean )
253 call disp%show("call setResized(var, size(mean, 1, IK))")
254 call setResized(var, size(mean, 1, IK))
255 call disp%show("call setVar(var, mean, sample, dim)")
256 call setVar(var, mean, sample, dim)
257 call disp%show("var")
258 call disp%show( var )
259 call disp%show("call setVar(var, getShifted(sample, dim, -mean), dim)")
260 call setVar(var, getShifted(sample, dim, -mean), dim)
261 call disp%show("var")
262 call disp%show( var )
263 call disp%skip()
264 end do
265 end block
266
267end program example
Allocate or resize (shrink or expand) an input allocatable scalar string or array of rank 1....
Generate count evenly spaced points over the interval [x1, x2] if x1 < x2, or [x2,...
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
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 resizing allocatable arrays of various typ...
This module contains procedures and generic interfaces for generating arrays with linear or logarithm...
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 properties related to the covariance ma...
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!Compute the variance of a 1-D sample.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6sample = getLinSpace(1._TKG, 9._TKG, 5_IK)
7sample
8+1.00000000, +3.00000000, +5.00000000, +7.00000000, +9.00000000
9mean = getMean(sample)
10mean
11+5.00000000
12call setVar(var, mean, sample)
13var
14+8.00000000
15call setVar(var, sample - mean)
16var
17+8.00000000
18call setVar(var, mean, sample, dim = 1_IK)
19var
20+8.00000000
21call setVar(var, sample - mean, dim = 1_IK)
22var
23+8.00000000
24
25sample = cmplx(getLinSpace(1., 9., 5_IK), -getLinSpace(1., 9., 5_IK), TKG)
26sample
27(+1.00000000, -1.00000000), (+3.00000000, -3.00000000), (+5.00000000, -5.00000000), (+7.00000000, -7.00000000), (+9.00000000, -9.00000000)
28mean = getMean(sample)
29mean
30(+5.00000000, -5.00000000)
31call setVar(var, mean, sample)
32var
33+16.0000000
34call setVar(var, sample - mean)
35var
36+16.0000000
37call setVar(var, mean, sample, dim = 1_IK)
38var
39+16.0000000
40call setVar(var, sample - mean, dim = 1_IK)
41var
42+16.0000000
43
44
45!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46!Compute the variance of a 1-D weighted sample.
47!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48
49sample = getLinSpace(1._TKG, 9._TKG, 5_IK)
50sample
51+1.00000000, +3.00000000, +5.00000000, +7.00000000, +9.00000000
52weight = getLinSpace(1._TKG, 9._TKG, size(sample, kind = IK))
53weight
54+1.00000000, +3.00000000, +5.00000000, +7.00000000, +9.00000000
55call setMean(mean, sample, weight, weisum)
56mean
57+6.59999990
58call setVar(var, mean, sample, weight, weisum)
59var
60+5.44000006
61call setVar(var, sample - mean, weight, weisum)
62var
63+5.44000006
64call setVar(var, mean, sample, 1_IK, weight, weisum)
65var
66+5.44000006
67call setVar(var, sample - mean, 1_IK, weight, weisum)
68var
69+5.44000006
70
71sample = cmplx(getLinSpace(1., 9., 5_IK), -getLinSpace(1., 9., 5_IK), TKG)
72sample
73(+1.00000000, -1.00000000), (+3.00000000, -3.00000000), (+5.00000000, -5.00000000), (+7.00000000, -7.00000000), (+9.00000000, -9.00000000)
74weight = getLinSpace(1._TKG, 9._TKG, size(sample, kind = IK))
75weight
76+1.00000000, +3.00000000, +5.00000000, +7.00000000, +9.00000000
77call setMean(mean, sample, weight, weisum)
78mean
79(+6.59999990, -6.59999990)
80call setVar(var, mean, sample, weight, weisum)
81var
82+10.8800001
83call setVar(var, sample - mean, weight, weisum)
84var
85+10.8800001
86call setVar(var, mean, sample, 1_IK, weight, weisum)
87var
88+10.8800001
89call setVar(var, sample - mean, 1_IK, weight, weisum)
90var
91+10.8800001
92
93
94!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95!Compute the variance of a 2-D array.
96!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97
98
99sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
100sample
101+4.74285126, +4.03135252, +8.56142998, +3.98327208, +6.31323099
102+3.68245649, +2.14310884, +6.39500475, +1.16531944, +7.60709333
103+6.61086130, +5.99097252, +1.80038309, +4.42868662, +2.13410234
104+2.96163750, +7.22902536, +3.68979216, +8.13751602, +5.70304155
105mean = [getMean(sample)]
106mean
107+4.86555767
108call setResized(var, size(mean, 1, IK))
109call setVar(var(1), mean(1), sample)
110var
111+4.64815474
112call setVar(var(1), sample - mean(1))
113var
114+4.64815474
115
116dim ! The observations axis.
117+1
118sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
119sample
120+8.74320221, +5.16978264, +7.36496687, +6.93166113, +1.30073500
121+4.30722427, +2.81342173, +7.31846237, +1.32430506, +8.63978767
122+1.15849495, +6.84464979, +2.50873089, +5.92331553, +3.16230297
123+3.95808697, +7.01295567, +4.07763290, +8.41999626, +3.05936527
124mean = getMean(sample, dim)
125mean
126+4.54175186, +5.46020222, +5.31744862, +5.64981937, +4.04054785
127call setResized(var, size(mean, 1, IK))
128call setVar(var, mean, sample, dim)
129var
130+7.37357044, +2.85438204, +4.40560627, +7.02546787, +7.59840393
131call setVar(var, getShifted(sample, dim, -mean), dim)
132var
133+7.37357044, +2.85438204, +4.40560627, +7.02546787, +7.59840393
134
135dim ! The observations axis.
136+2
137sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
138sample
139+8.41918182, +8.17148685, +5.54950190, +3.37251329, +7.76090193
140+3.47498894, +3.08964491, +1.44948864, +1.86618423, +1.72866392
141+5.40517235, +3.11763573, +8.08383560, +2.63919258, +7.89545488
142+3.67148685, +7.03820467, +8.12860394, +5.05453539, +2.64575911
143mean = getMean(sample, dim)
144mean
145+6.65471649, +2.32179427, +5.42825842, +5.30771780
146call setResized(var, size(mean, 1, IK))
147call setVar(var, mean, sample, dim)
148var
149+3.72638679, +0.647950768, +5.25150967, +4.15587234
150call setVar(var, getShifted(sample, dim, -mean), dim)
151var
152+3.72638679, +0.647950768, +5.25150967, +4.15587234
153
154
155sample = cmplx(getUnifRand(1., 9., 4_IK, 5_IK), -getUnifRand(1., 9., 4_IK, 5_IK), TKG)
156sample
157(+1.80287361, -8.33470821), (+7.33898687, -6.95565701), (+4.21613455, -8.96492290), (+7.26286030, -5.34129763), (+3.14539528, -6.49214602)
158(+1.18732023, -1.49996376), (+7.30265045, -5.97813511), (+1.05822086, -4.07436514), (+8.88326359, -6.09228039), (+7.71417999, -1.90151596)
159(+5.69305658, -6.06886864), (+6.73127890, -7.42602396), (+6.75808620, -3.96110010), (+8.54331684, -2.70935678), (+2.99343443, -5.88224506)
160(+3.76441383, -2.45355463), (+4.41224813, -1.86188269), (+4.86450005, -1.40185976), (+8.13259602, -6.96013212), (+5.89485359, -3.34007454)
161mean = [getMean(sample)]
162mean
163(+5.38498354, -4.88500452)
164call setResized(var, size(mean, 1, IK))
165call setVar(var(1), mean(1), sample)
166var
167+11.1495228
168call setVar(var(1), sample - mean(1))
169var
170+11.1495228
171
172dim ! The observations axis.
173+1
174sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
175sample
176(+4.97402382, +0.00000000), (+1.26916504, +0.00000000), (+2.27789688, +0.00000000), (+2.11614513, +0.00000000), (+3.38488102, +0.00000000)
177(+4.16461515, +0.00000000), (+3.11514091, +0.00000000), (+4.56768036, +0.00000000), (+8.84822559, +0.00000000), (+3.36519194, +0.00000000)
178(+1.19947958, +0.00000000), (+8.75055122, +0.00000000), (+1.99092102, +0.00000000), (+8.35781670, +0.00000000), (+5.21265459, +0.00000000)
179(+6.43764591, +0.00000000), (+1.04739285, +0.00000000), (+1.70489073, +0.00000000), (+7.62419891, +0.00000000), (+2.81497478, +0.00000000)
180mean = getMean(sample, dim)
181mean
182(+4.19394112, +0.00000000), (+3.54556251, +0.00000000), (+2.63534737, +0.00000000), (+6.73659658, +0.00000000), (+3.69442558, +0.00000000)
183call setResized(var, size(mean, 1, IK))
184call setVar(var, mean, sample, dim)
185var
186+3.65260005, +9.67500114, +1.28567910, +7.30593538, +0.820666432
187call setVar(var, getShifted(sample, dim, -mean), dim)
188var
189+3.65260005, +9.67500114, +1.28567910, +7.30593538, +0.820666432
190
191dim ! The observations axis.
192+2
193sample = getUnifRand(1._TKG, 9._TKG, 4_IK, 5_IK)
194sample
195(+4.56532431, +0.00000000), (+6.36860704, +0.00000000), (+8.09331512, +0.00000000), (+2.19367886, +0.00000000), (+1.38604736, +0.00000000)
196(+6.51252604, +0.00000000), (+2.45001841, +0.00000000), (+1.96435785, +0.00000000), (+5.34889841, +0.00000000), (+6.78358173, +0.00000000)
197(+3.82921648, +0.00000000), (+1.85528898, +0.00000000), (+1.96496534, +0.00000000), (+2.51438522, +0.00000000), (+2.70814562, +0.00000000)
198(+2.59503746, +0.00000000), (+8.83718967, +0.00000000), (+7.45172834, +0.00000000), (+4.26850986, +0.00000000), (+4.94268847, +0.00000000)
199mean = getMean(sample, dim)
200mean
201(+4.52139425, +0.00000000), (+4.61187696, +0.00000000), (+2.57440042, +0.00000000), (+5.61903095, +0.00000000)
202call setResized(var, size(mean, 1, IK))
203call setVar(var, mean, sample, dim)
204var
205+6.28428030, +4.11099195, +0.496917069, +5.02824211
206call setVar(var, getShifted(sample, dim, -mean), dim)
207var
208+6.28428030, +4.11099195, +0.496917069, +5.02824211
209
210
Test:
test_pm_sampleVar
Todo:
Normal Priority: The examples of this generic interface need to be extended to weighted samples.
Todo:
Very Low Priority: The functionality of this interface can be expanded in the future to include the computation of the variance of higher dimensional input sample and whole sample input arrays of arbitrary shape.


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

Definition at line 2618 of file pm_sampleVar.F90.


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