StatisticalDiagrams package¶
Submodules¶
StatisticalDiagrams.StatisticalDiagrams module¶
Standard versions of statistical summary diagrams (Taylor and Target).
Examples:
The following example plots a Taylor and Target Diagrams for three randomly
generated datasets with respect to randomly distributed reference data: one
uncorrelated to the reference data with no added bias, one weakly correlated
with substantially smaller scale and added negative bias and one strongly
correlated one with substantially larger scale and added positive bias.
Four plots are generated, two using the TargetStatistics and
TaylorStatistics classes that internally computes the summary statistics
from the datasets and two using the TargetDiagram and TaylorDiagram
class and pre-computed summary statistics. The example shows that the outcome is
equivalent.
from StatisticalDiagrams import *
from numpy.random import randn
from matplotlib.pyplot import figure,show
ref=randn(10)
a=randn(10)
b=.5*(.25*ref+.75*randn(10)) - .5
c=2.*(.75*ref+.25*randn(10)) + .5
f=figure(figsize=[12,10])
ax1=f.add_subplot(221)
TarS=TargetStatistics(a,ref,ax=ax1)
TarS(b,ref)
TarS(c,ref)
ax2=f.add_subplot(222)
TayS=TaylorStatistics(a,ref,ax=ax2)
TayS(b,ref)
TayS(c,ref)
std1=a.std()
std2=b.std()
std3=c.std()
refstd=ref.std()
R1,p=pearsonr(a,ref)
E1=(a.mean()-ref.mean())/refstd
G1=std1/refstd
R2,p=pearsonr(b,ref)
E2=(b.mean()-ref.mean())/refstd
G2=std2/refstd
R3,p=pearsonr(c,ref)
E3=(c.mean()-ref.mean())/refstd
G3=std3/refstd
ax3=f.add_subplot(223)
TarD=TargetDiagram(G1,E1,R1,ax=ax3)
TarD(G2,E2,R2,)
TarD(G3,E3,R3,)
ax4=f.add_subplot(224)
TayD=TaylorDiagram(G1,E1,R1,ax=ax4)
TayD(G2,E2,R2,)
TayD(G3,E3,R3,)
show()
-
class
StatisticalDiagrams.StatisticalDiagrams.Stats(gam, E0, rho)¶ Bases:
objectBase class for statistical summary diagrams, using precomuted metrics rather than the full datasets as input.
-
__call__(gam, E0, rho)¶ Loading new metrics.
Parameters: - gam (float) – STD ratio (Data/Reference)
- E0 (float) – Mean bias
- rho (float) – Correlation Coefficient
-
__dict__= mappingproxy({'__module__': 'StatisticalDiagrams.StatisticalDiagrams', '__doc__': 'Base class for statistical summary diagrams, using precomuted metrics rather than the full datasets as input.', '__init__': <function Stats.__init__>, '__call__': <function Stats.__call__>, 'addCSV': <function Stats.addCSV>, 'writeCSV': <function Stats.writeCSV>, '__str__': <function Stats.__str__>, '__dict__': <attribute '__dict__' of 'Stats' objects>, '__weakref__': <attribute '__weakref__' of 'Stats' objects>})¶
-
__init__(gam, E0, rho)¶ Loading the necessary metrics.
Parameters: - gam (float) – STD ratio (Data/Reference)
- E0 (float) – Normalised mean bias
- rho (float) – Correlation Coefficient
-
__module__= 'StatisticalDiagrams.StatisticalDiagrams'¶
-
__str__()¶ Return str(self).
-
__weakref__¶ list of weak references to the object (if defined)
-
addCSV()¶ Add new set of summary statistics to csv attribute.
-
writeCSV(filename, *opts, **keys)¶ Write csv attribute to file.
Parameters: - filename (string) – filename for csv filename
- *opts – positional arguments passed to open function
- **args” keyword arguments passed to `open` function
-
-
class
StatisticalDiagrams.StatisticalDiagrams.StatsDiagram(data, refdata, *opts, **keys)¶ Bases:
objectBase class for statistical summary diagrams based on two arrays of the same size that will be compared on a point to point base. The first array is considered the data to be evaluated, the second is the reference data. It computes all the basic metrics using the
_statsfunction:Variables: - std (float) – the standard deviation of the reference data
- E0 (float) – the mean normalised bias of the two data sets
- gamma (float) – the ratio of the std of data over reference data
- R (float) – Pearson correlation
- p (float) – p-value of Pearson correlation
- E (float) – the normalised root-mean square difference of the two dataset
- csv (string) – collects the summary statistics of the instance to be written to csv file, when desired.
-
__call__(data, refdata, *opts, **keys)¶ Recomputes summary statistics for new input and reference data.
Parameters: - data (float array) – input data
- refdata (float array) – references data, same shape as input data
- *opts – positional arguments passed to summary statistics function
- **keys – keyword arguments passed to summary statistics function
-
__dict__= mappingproxy({'__module__': 'StatisticalDiagrams.StatisticalDiagrams', '__doc__': 'Base class for statistical summary diagrams based on two arrays of\n the same size that will be compared on a point to point base.\n The first array is considered the data to be evaluated, the second is\n the reference data. It computes all the basic metrics using the\n ``_stats`` function:\n\n Attributes:\n std (float): the standard deviation of the reference data\n E0 (float): the mean normalised bias of the two data sets\n gamma (float): the ratio of the std of data over reference data\n R (float): Pearson correlation\n p (float): p-value of Pearson correlation\n E (float): the normalised root-mean square difference of the two\n dataset\n csv (string): collects the summary statistics of the instance to be\n written to csv file, when desired.\n ', '__init__': <function StatsDiagram.__init__>, '__call__': <function StatsDiagram.__call__>, '_stats': <function StatsDiagram._stats>, 'addCSV': <function StatsDiagram.addCSV>, 'writeCSV': <function StatsDiagram.writeCSV>, '__str__': <function StatsDiagram.__str__>, '__dict__': <attribute '__dict__' of 'StatsDiagram' objects>, '__weakref__': <attribute '__weakref__' of 'StatsDiagram' objects>})¶
-
__init__(data, refdata, *opts, **keys)¶ Calls summary statistics function from input data with respect to reference data. Initialises csv attribute.
Parameters: - data (float array) – input data
- refdata (float array) – references data, same shape as input data
- *opts – positional arguments passed to summary statistics function
- **keys – keyword arguments passed to summary statistics function
-
__module__= 'StatisticalDiagrams.StatisticalDiagrams'¶
-
__str__()¶ Return str(self).
-
__weakref__¶ list of weak references to the object (if defined)
-
addCSV()¶ Add new set of summary statistics to csv attribute.
-
writeCSV(filename, *opts, **keys)¶ Write csv attribute to file.
Parameters: - filename (string) – filename for csv filename
- *opts – positional arguments passed to open function
- **args” keyword arguments passed to `open` function
-
class
StatisticalDiagrams.StatisticalDiagrams.Target(ax)¶ Bases:
objectBase class providing a function to draw the grid for Target Diagrams.
Parameters: ax (matplotlib.axes.Axes) – axes containing the diagram. -
__dict__= mappingproxy({'__module__': 'StatisticalDiagrams.StatisticalDiagrams', '__doc__': 'Base class providing a function to draw the grid for Target Diagrams.\n\n Args:\n ax (matplotlib.axes.Axes): axes containing the diagram.\n ', '__init__': <function Target.__init__>, 'drawTargetGrid': <function Target.drawTargetGrid>, '__dict__': <attribute '__dict__' of 'Target' objects>, '__weakref__': <attribute '__weakref__' of 'Target' objects>})¶
-
__init__(ax)¶ Parameters: ax (matplotlib.axes.Axes) – axes to use, if False creates new Axes
-
__module__= 'StatisticalDiagrams.StatisticalDiagrams'¶
-
__weakref__¶ list of weak references to the object (if defined)
-
drawTargetGrid()¶ Draws Target Diagram grid.
-
-
class
StatisticalDiagrams.StatisticalDiagrams.TargetDiagram(gam, E0, rho, marker='o', s=40, antiCorrelation=False, ax=False, *opts, **keys)¶ Bases:
StatisticalDiagrams.StatisticalDiagrams.Target,StatisticalDiagrams.StatisticalDiagrams.StatsClass for drawing a Target diagram from pre-calculated metrics.
Variables: - std (float) – the standard deviation of the reference data
- E0 (float) – normalised mean bias of the two data sets
- gama (float) – the ratio of the std of data over reference data
- R (float) – Pearson correlation
- p (float) – p-value of Pearson correlation
- E (float) – normalised root-mean square difference of the two dataset
- csv (string) – collects the summary statistics of the instance to be written to csv file, when desired.
- ax (matplotlib.axes.Axes) – axes containing the diagram.
-
__call__(gam, E0, rho, marker='o', s=40, *opts, **keys)¶ Adds points to the diagram adjusting the colour codes
Parameters: - gam (float) – STD ratio (Data/Reference)
- E0 (float) – normalised mean bias
- rho (float) – Correlation Coefficient
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
-
__init__(gam, E0, rho, marker='o', s=40, antiCorrelation=False, ax=False, *opts, **keys)¶ Initialises the class given the pre-calculated metrics and draws the diagram grid with the first point. Markers in the diagram are colour-coded using the mean bias.
Parameters: - gam (float) – STD ratio (Data/Reference)
- E0 (float) – normalised mean bias
- rho (float) – Correlation Coefficient
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- antiCorrelation (boolean) – if True, show negative correlations
- ax (matplotlib.axes.Axes) – axes to use, if False creates new Axes
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
-
__module__= 'StatisticalDiagrams.StatisticalDiagrams'¶
-
add(gam, E0, R, marker='o', s=40, *opts, **keys)¶ Function to add additional points to the diagram, usually invoked by means of the
__call__function.Parameters: - gam (float) – STD ratio (Data/Reference)
- E0 (float) – normalised mean bias
- R (float) – Correlation Coefficient
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- opts – positional arguments passed to matplotlib.pyplot.scatter function
- keys – keyword arguments passed to
matplotlib.pyplot.scatterfunction
Returns: matplotlib.collections.PathCollection instance from scatter call
-
labels(lstr, *opts, **keys)¶ Adds labels
lstr`to the points in the diagram.Parameters: - lstr (string) – string for lable
- *opts – positional arguments passed to
matplotlib.pyplot.textfunction. - **keys – keyword arguments passed to
matplotlib.pyplot.textfunction.
-
class
StatisticalDiagrams.StatisticalDiagrams.TargetStatistics(data, refdata, marker='o', s=40, antiCorrelation=False, ax=False, *opts, **keys)¶ Bases:
StatisticalDiagrams.StatisticalDiagrams.StatsDiagram,StatisticalDiagrams.StatisticalDiagrams.TargetDiagramClass for drawing a Taylor diagram from input and reference data.
Variables: - std (float) – the standard deviation of the reference data
- E0 (float) – normalised mean bias of the two data sets
- gama (float) – the ratio of the std of data over reference data
- R (float) – Pearson correlation
- p (float) – the Pearson correlation with p-value
- E (float) – mormalised root-mean square difference of the two dataset
- csv (string) – collects the summary statistics of the instance to be written to csv file, when desired.
- ax (matplotlib.axes.Axes) – axes containing the diagram.
-
__call__(data, refdata, marker='o', s=40, *opts, **keys)¶ Adds points to the diagram adjusting the colour codes.
Parameters: - data (float array) – input data
- refdata (float array) – references data, same shape as input data
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
-
__init__(data, refdata, marker='o', s=40, antiCorrelation=False, ax=False, *opts, **keys)¶ Initialises the class computing all necessary metrics and draws the diagram grid with the first point. Markers in the diagram are colour-coded using the mean bias.
Parameters: - data (float array) – input data
- refdata (float array) – references data, same shape as input data
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- antiCorrelation (boolean) – if True, show negative correlations
- ax (matplotlib.axes.Axes) – axes to use, if False creates new Axes
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
-
__module__= 'StatisticalDiagrams.StatisticalDiagrams'¶
-
class
StatisticalDiagrams.StatisticalDiagrams.Taylor(ax)¶ Bases:
objectBase class providing a function to draw the grid for Taylor Diagrams for inheritance along with stats class.
Parameters: ax (matplotlib.axes.Axes) – axes containing the diagram. -
__dict__= mappingproxy({'__module__': 'StatisticalDiagrams.StatisticalDiagrams', '__doc__': 'Base class providing a function to draw the grid for Taylor Diagrams for\n inheritance along with stats class.\n\n Args:\n ax (matplotlib.axes.Axes): axes containing the diagram.\n ', '__init__': <function Taylor.__init__>, 'drawTaylorGrid': <function Taylor.drawTaylorGrid>, '__dict__': <attribute '__dict__' of 'Taylor' objects>, '__weakref__': <attribute '__weakref__' of 'Taylor' objects>})¶
-
__init__(ax)¶ Parameters: ax (matplotlib.axes.Axes) – axes to use, if False creates new Axes
-
__module__= 'StatisticalDiagrams.StatisticalDiagrams'¶
-
__weakref__¶ list of weak references to the object (if defined)
-
drawTaylorGrid(R, dr, antiCorrelation)¶ Draws Taylor Diagram grid.
Parameters: - R (float) – length of rays from origin in Taylor plot
- dr (float) – step-size of circles around ideal point (1,0) in Taylor plot
- antiCorrelation (boolean) – plot also anticorrelation half of diagram
-
-
class
StatisticalDiagrams.StatisticalDiagrams.TaylorDiagram(gam, E0, rho, R=2.5, dr=0.5, antiCorrelation=True, marker='o', s=40, ax=False, *opts, **keys)¶ Bases:
StatisticalDiagrams.StatisticalDiagrams.Taylor,StatisticalDiagrams.StatisticalDiagrams.StatsClass for drawing a Taylor diagram from pre-calculated metrics.
Variables: - std (float) – the standard deviation of the reference data
- E0 (float) – normalised mean bias of the two data sets
- gama (float) – the ratio of the std of data over reference data
- R (float) – Pearson correlation
- p (float) – p-value of Pearson correlation
- E (float) – normalised root-mean square difference of the two dataset
- csv (string) – collects the summary statistics of the instance to be written to csv file, when desired.
- ax (matplotlib.axes.Axes) – axes containing the diagram.
-
__call__(gam, E0, rho, marker='o', s=40, *opts, **keys)¶ Adds points to the diagram adjusting the colour codes.
Parameters: - gam (float) – STD ratio (Data/Reference)
- E0 (float) – Normalised mean bias
- rho (float) – Correlation Coefficient
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
-
__init__(gam, E0, rho, R=2.5, dr=0.5, antiCorrelation=True, marker='o', s=40, ax=False, *opts, **keys)¶ Initialises the class given the pre-calculated metrics and draws the diagram grid with the first point. Markers in the diagram are colour-coded using the mean bias.
Parameters: - gam (float) – STD ratio (Data/Reference)
- E0 (float) – Normalised mean bias
- rho (float) – Correlation Coefficient
- R (float) – length of rays from origin in Taylor plot
- dr (float) – step-size of circles around ideal point (1,0) in Taylor plot
- antiCorrelation (boolean) – if True, show negative correlations
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- ax (matplotlib.axes.Axes) – axes to use, if False creates new Axes
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
-
__module__= 'StatisticalDiagrams.StatisticalDiagrams'¶
-
add(gam, E0, R, marker='o', s=40, *opts, **keys)¶ Function to add additional points to the diagram, usually invoked by means of the
__call__function.Parameters: - gam (float) – STD ratio (Data/Reference)
- E0 (float) – Normalised mean bias
- R (float) – Correlation Coefficient
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- opts – positional arguments passed to matplotlib.pyplot.scatter function
- keys – keyword arguments passed to
matplotlib.pyplot.scatterfunction
Returns: matplotlib.collections.PathCollection instance from scatter call
-
labels(lstr, *opts, **keys)¶ Adds labels
lstr`to the points in the diagram.Parameters: - lstr (string) – string for lable
- *opts – positional arguments passed to
matplotlib.pyplot.textfunction. - **keys – keyword arguments passed to
matplotlib.pyplot.textfunction.
-
class
StatisticalDiagrams.StatisticalDiagrams.TaylorStatistics(data, refdata, R=2.5, dr=0.5, antiCorrelation=True, marker='o', s=40, ax=False, *opts, **keys)¶ Bases:
StatisticalDiagrams.StatisticalDiagrams.StatsDiagram,StatisticalDiagrams.StatisticalDiagrams.TaylorDiagramClass for drawing a Taylor diagram from input and reference data.
Variables: - std (float) – the standard deviation of the reference data
- E0 (float) – normalised mean bias of the two data sets
- gama (float) – the ratio of the std of data over reference data
- R (float) – Pearson correlation
- p (float) – the Pearson correlation with p-value
- E (float) – normalised root-mean square difference of the two dataset
- csv (string) – collects the summary statistics of the instance to be written to csv file, when desired.
- ax (matplotlib.axes.Axes) – axes containing the diagram.
-
__call__(data, refdata, marker='o', s=40, *opts, **keys)¶ Adds points to the diagram adjusting the colour codes.
Parameters: - data (float array) – input data
- refdata (float array) – references data, same shape as input data
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
-
__init__(data, refdata, R=2.5, dr=0.5, antiCorrelation=True, marker='o', s=40, ax=False, *opts, **keys)¶ Initialises the class computing all necessary metrics and draws the diagram grid with the first point. Markers in the diagram are colour-coded using the mean bias.
Parameters: - data (float array) – input data
- refdata (float array) – references data, same shape as input data
- R (float) – length of rays from origin in Taylor plot
- dr (float) – step-size of circles around ideal point (1,0) in Taylor plot
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- antiCorrelation (boolean) – if True, show negative correlations
- ax (matplotlib.axes.Axes) – axes to use, if False creates new Axes
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
-
__module__= 'StatisticalDiagrams.StatisticalDiagrams'¶
-
StatisticalDiagrams.StatisticalDiagrams.rmsds(gamma, R)¶ Computes normalised unbiased root-mean-square difference from correlatio and standard deviation ratio.
Parameters: - gamma (float) – ratio of standard deviations
- R (float) – correlation coefficient
Returns: normalised unbiased root-mean-square difference.
StatisticalDiagrams.robust module¶
Target Diagrams using robust statistics:
- average: median
- scale: inter-quartile arange
- scale difference: median absolute error
- correlation: spearman
Example:
The following example plots a target diagram based on robust statistics for
three randomly generated datasets with respect to randomly distributed reference
data: one uncorrelated to the reference data with no added bias, one weakly
correlated with substantially smaller scale and added negative bias and one
strongly correlated one with substantially larger scale and added positive bias.
Two plots are generated, one using the TargetStatistics class that
internally computes the summary statistics from the datasets and one using the
TargetDiagram class and pre-computed summary statistics. The example shows
that the outcome is equivalent.
from numpy.random import randn
from numpy import median
from scipy.stats import spearmanr
from StatisticalDiagrams.robust import *
from StatisticalDiagrams.RobustStatistics import MAE,IQR
from matplotlib.pyplot import figure,show
ref=randn(10)
a=randn(10)
b=.5*(.25*ref+.75*randn(10)) - .5
c=2.*(.75*ref+.25*randn(10)) + .5
f=figure(figsize=[12,5])
ax1=f.add_subplot(121)
TD=TargetStatistics(a,ref,precision=1.e-15,ax=ax1)
TD(b,ref,precision=1.e-15)
TD(c,ref,precision=1.e-15)
R1,p=spearmanr(a,ref)
scale1=IQR(a)
refscale=IQR(ref)
E0_1=median(a-ref)/refscale
E1=MAE(a-E0_1*refscale,ref)/refscale
R2,p=spearmanr(b,ref)
E0_2=median(b-ref)/refscale
scale2=IQR(b)
E2=MAE(b-E0_2*refscale,ref)/refscale
R3,p=spearmanr(c,ref)
E0_3=median(c-ref)/refscale
scale3=IQR(c)
E3=MAE(c-E0_3*refscale,ref)/refscale
ax2=f.add_subplot(122)
TD=TargetDiagram(scale1/refscale,E0_1,E1,R1,ax=ax2)
TD(scale2/refscale,E0_2,E2,R2)
TD(scale3/refscale,E0_3,E3,R3)
show()
-
class
StatisticalDiagrams.robust.Stats(gam, E0, E, rho)¶ Bases:
objectBase class for statistical summary diagrams, using precomuted metrics rather than the full datasets as input.
-
__call__(gam, E0, E, rho)¶ Loading new metrics.
Parameters: - gam (float) – scale ratio (Data/Reference)
- E0 (float) – bias
- rho (float) – correlation coefficient
-
__dict__= mappingproxy({'__module__': 'StatisticalDiagrams.robust', '__doc__': 'Base class for statistical summary diagrams, using precomuted metrics rather than the full datasets as input.', '__init__': <function Stats.__init__>, '__call__': <function Stats.__call__>, 'addCSV': <function Stats.addCSV>, 'writeCSV': <function Stats.writeCSV>, '__str__': <function Stats.__str__>, '__dict__': <attribute '__dict__' of 'Stats' objects>, '__weakref__': <attribute '__weakref__' of 'Stats' objects>})¶
-
__init__(gam, E0, E, rho)¶ Loading the necessary metrics.
Parameters: - gam (float) – scale ratio (Data/Reference)
- E0 (float) – bias
- rho (float) – correlation coefficient
-
__module__= 'StatisticalDiagrams.robust'¶
-
__str__()¶ Return str(self).
-
__weakref__¶ list of weak references to the object (if defined)
-
addCSV()¶ Add new set of summary statistics to csv attribute.
-
writeCSV(filename, *opts, **keys)¶ Write csv attribute to file.
Parameters: - filename (string) – filename for csv filename
- *opts – positional arguments passed to open function
- **args” keyword arguments passed to `open` function
-
-
class
StatisticalDiagrams.robust.StatsDiagram(data, refdata, precision)¶ Bases:
objectBase class for robust statistical summary diagrams based on two arrays of the same size that will be compared on a point to point base. The first array is considered the data to be evaluated, the second is the reference data. It computes all the basic metrics using the
_statsfunction:Variables: - scale (float) – scale of reference data
- E0 (float) – the median bias of the two data sets, relative to scale
- gama (float) – the ratio of the scales of data over reference data
- R (float) – Spearman correlation
- p (float) – the Spearman correlation with p-value
- E (float) – the scale difference of the two dataset
- csv (string) – collects the summary statistics of the instance to be written to csv file, when desired.
-
__call__(data, refdata, precision)¶ Recomputes summary statistics for new input and reference data.
Parameters: - data (float array) – input data
- refdata (float array) – references data, same shape as input data
- precision (float arrya) – reference data precision
- *opts – positional arguments passed to summary statistics function
- **keys – keyword arguments passed to summary statistics function
-
__dict__= mappingproxy({'__module__': 'StatisticalDiagrams.robust', '__doc__': 'Base class for robust statistical summary diagrams based on two arrays of\n the same size that will be compared on a point to point base.\n The first array is considered the data to be evaluated, the second is\n the reference data. It computes all the basic metrics using the\n ``_stats`` function:\n\n Attributes:\n scale (float): scale of reference data\n E0 (float): the median bias of the two data sets, relative to scale\n gama (float): the ratio of the scales of data over reference data\n R (float): Spearman correlation\n p (float): the Spearman correlation with p-value\n E (float): the scale difference of the two dataset\n csv (string): collects the summary statistics of the instance to be\n written to csv file, when desired.\n ', '__init__': <function StatsDiagram.__init__>, '__call__': <function StatsDiagram.__call__>, '_stats': <function StatsDiagram._stats>, 'addCSV': <function StatsDiagram.addCSV>, 'writeCSV': <function StatsDiagram.writeCSV>, '__str__': <function StatsDiagram.__str__>, '__dict__': <attribute '__dict__' of 'StatsDiagram' objects>, '__weakref__': <attribute '__weakref__' of 'StatsDiagram' objects>})¶
-
__init__(data, refdata, precision)¶ Calls summary statistics function from input data with respect to reference data. Initialises csv attribute. In the robust case a precision of the reference data is required. This represents the measurment precision and ensures that the scale measure can not be lesser than the precision. In case of the latter a warning is issued and the scale measure of the reference is replaced by the precision.
Parameters: - data (float array) – input data
- refdata (float array) – references data, same shape as input data
- precision (float arrya) – reference data precision
- *opts – positional arguments passed to summary statistics function
- **keys – keyword arguments passed to summary statistics function
-
__module__= 'StatisticalDiagrams.robust'¶
-
__str__()¶ Return str(self).
-
__weakref__¶ list of weak references to the object (if defined)
-
addCSV()¶ Add new set of summary statistics to csv attribute.
-
writeCSV(filename, *opts, **keys)¶ Write csv attribute to file.
Parameters: - filename (string) – filename for csv filename
- *opts – positional arguments passed to open function
- **args” keyword arguments passed to `open` function
-
class
StatisticalDiagrams.robust.Target(ax)¶ Bases:
objectBase class providing a function to draw the grid for Target Diagrams.
Parameters: ax (matplotlib.axes.Axes) – axes containing the diagram. -
__dict__= mappingproxy({'__module__': 'StatisticalDiagrams.robust', '__doc__': 'Base class providing a function to draw the grid for Target Diagrams.\n\n Args:\n ax (matplotlib.axes.Axes): axes containing the diagram.\n ', '__init__': <function Target.__init__>, 'drawTargetGrid': <function Target.drawTargetGrid>, '__dict__': <attribute '__dict__' of 'Target' objects>, '__weakref__': <attribute '__weakref__' of 'Target' objects>})¶
-
__init__(ax)¶ Parameters: ax (matplotlib.axes.Axes) – axes to use, if False creates new Axes
-
__module__= 'StatisticalDiagrams.robust'¶
-
__weakref__¶ list of weak references to the object (if defined)
-
drawTargetGrid()¶ Draws Target Diagram grid.
-
-
class
StatisticalDiagrams.robust.TargetDiagram(gam, E0, E, rho, marker='o', s=40, antiCorrelation=False, ax=False, *opts, **keys)¶ Bases:
StatisticalDiagrams.robust.Target,StatisticalDiagrams.robust.StatsClass for drawing a Target diagram from pre-calculated metrics.
Variables: - scale (float) – scale of reference data
- E0 (float) – the median bias of the two data sets, relative to scale
- gama (float) – the ratio of the scales of data over reference data
- R (float) – Spearman correlation
- p (float) – the Spearman correlation with p-value
- E (float) – the scale difference of the two dataset
- csv (string) – collects the summary statistics of the instance to be written to csv file, when desired.
- ax (matplotlib.axes.Axes) – axes containing the diagram.
-
__call__(gam, E0, E, rho, marker='o', s=40, *opts, **keys)¶ Adds points to the diagram adjusting the colour codes
Parameters: - gam (float) – scale ratio (Data/Reference)
- E0 (float) – bias, relative to scale
- E (float) – scale difference, relative to scale
- rho (float) – correlation coefficient
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
-
__init__(gam, E0, E, rho, marker='o', s=40, antiCorrelation=False, ax=False, *opts, **keys)¶ Initialises the class given the pre-calculated metrics and draws the diagram grid with the first point. Markers in the diagram are colour-coded using the bias.
Parameters: - gam (float) – scale ratio (Data/Reference)
- E0 (float) – bias, relative to scale
- E (float) – scale difference, relative to scale
- rho (float) – correlation coefficient
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- antiCorrelation (boolean) – if True, show negative correlations
- ax (matplotlib.axes.Axes) – axes to use, if False creates new Axes
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
-
__module__= 'StatisticalDiagrams.robust'¶
-
add(gam, E0, E, R, marker='o', s=40, *opts, **keys)¶ Function to add additional points to the diagram, usually invoked by means of the
__call__function.Parameters: - gam (float) – scale ratio (Data/Reference)
- E0 (float) – bias, relative to scale
- E (float) – scale difference, relative to scale
- R (float) – correlation coefficient
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
Returns: matplotlib.collections.PathCollection instance from scatter call
-
labels(lstr, *opts, **keys)¶ Adds labels
lstr`to the points in the diagram.Parameters: - lstr (string) – string for lable
- *opts – positional arguments passed to
matplotlib.pyplot.textfunction. - **keys – keyword arguments passed to
matplotlib.pyplot.textfunction.
-
class
StatisticalDiagrams.robust.TargetStatistics(data, refdata, precision, marker='o', s=40, antiCorrelation=False, ax=False, *opts, **keys)¶ Bases:
StatisticalDiagrams.robust.StatsDiagram,StatisticalDiagrams.robust.TargetDiagramClass for drawing a Target diagram from input and reference data.
Variables: - scale (float) – scale of reference data
- E0 (float) – the median bias of the two data sets, relative to scale
- gama (float) – the ratio of the scales of data over reference data
- R (float) – Spearman correlation
- p (float) – the Spearman correlation with p-value
- E (float) – the scale difference of the two dataset, relative to scale
- csv (string) – collects the summary statistics of the instance to be written to csv file, when desired.
- cbar (matplotlib.colors.colorbar) – colorbar of target plot
- ax (matplotlib.axes.Axes) – axes containing the diagram.
-
__call__(data, refdata, precision, marker='o', s=40, *opts, **keys)¶ Adds points to the diagram adjusting the colour codes.
Parameters: - data (float array) – input data
- refdata (float array) – references data, same shape as input data
- precision (float arrya) – reference data precision
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- *opts – positional arguments passed to summary statistics function
- **keys – keyword arguments passed to summary statistics function
-
__init__(data, refdata, precision, marker='o', s=40, antiCorrelation=False, ax=False, *opts, **keys)¶ Calls summary statistics function from input data with respect to reference data. Initialises csv attribute. In the robust case a precision of the reference data is required. This represents the measurment precision and ensures that the scale measure can not be lesser than the precision. In case of the latter a warning is issued and the scale measure of the reference is replaced by the precision.
Parameters: - data (float array) – input data
- refdata (float array) – references data, same shape as input data
- precision (float arrya) – reference data precision
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- antiCorrelation (boolean) – if True, show negative correlations
- ax (matplotlib.axes.Axes) – axes to use, if False creates new Axes
- *opts – positional arguments passed to summary statistics function
- **keys – keyword arguments passed to summary statistics function
-
__module__= 'StatisticalDiagrams.robust'¶
-
add(gam, E0, E, R, marker='o', s=40, *opts, **keys)¶ Function to add additional points to the diagram, usually invoked by means of the
__call__function.Parameters: - gam (float) – scale ratio (Data/Reference)
- E0 (float) – bias relative to scale
- E (float) – scale difference, relative to scale
- R (float) – correlation coefficient
- marker – shape used to show points, should be a hollow shape as it is filled with colour code for bias.
- s (integer scalar or array_like) – marker size in points
- opts – positional arguments passed to
addfunction - keys – keyword arguments passed to
addfunction
Returns: matplotlib.collections.PathCollection instance from scatter call
-
labels(lstr, *opts, **keys)¶ Adds labels
lstr`to the points in the diagram.Parameters: - lstr (string) – string for lable
- *opts – positional arguments passed to
matplotlib.pyplot.textfunction. - **keys – keyword arguments passed to
matplotlib.pyplot.textfunction.
StatisticalDiagrams.RobustStatistics module¶
-
StatisticalDiagrams.RobustStatistics.IQR(data)¶ Inter-quartile range of input data.
Parameters: data (float array-like) – input data Returns: Inter-quartile range (float).
-
StatisticalDiagrams.RobustStatistics.MAD(data, c=1.4826)¶ Computes Median Absolute Deviation:
MAD=c*med|xi-med(xi)|
Parameters: - data (float array-like) – input data
- c (float) – scaling coefficient
Returns: Median absolute deviation (float).
-
StatisticalDiagrams.RobustStatistics.MAE(x, y)¶ Computes Median Absolute Error:
MAE=med|xi-yi||
Parameters: xi,yi (float array-like) – datasets to compare, same shape Returns: Median Absolute Error (float).
-
StatisticalDiagrams.RobustStatistics.MID(data)¶ Median interpoint distance, merory efficient version adopted from: Rousseeuw, P. J. & Croux C. Alternatives to the Median Absolute Deviation Journal of the American Statistical Association 1993, 88, 1273-1283 Croux, C. & Rousseeuw, P. J. Time-efficient algorithms for two highly robust estimators of scale Computational Statistics 1992, 1
Parameters: data (float array-like) – input data Returns: Median interpoint distance (float).
-
StatisticalDiagrams.RobustStatistics.MIDExplicit(data)¶ Median Interpoint Difference:
MID=med|xi-xj|,i<j
Parameters: data (float or integer array-like) – input data Returns: Median interpoint distance.
-
StatisticalDiagrams.RobustStatistics.MedianBias(x, y)¶ Computes Median Bias:
MB=med|xi|-med|yi||
Parameters: x,y (float array-like) – datasets to compare, same shape Returns: Median bias (float).
-
StatisticalDiagrams.RobustStatistics.Qdist(s1, s2, distFun)¶ Computes distance scale between to sets of samples based on Sn scale.
Parameters: - s1, s2 (float array-likes) – input datasets, same shape.
- distFun – distance function to be used
Returns: Median distance based on
-
StatisticalDiagrams.RobustStatistics.Qn(data)¶ Robust scale measure:
Qn = c*dn*{|xi-xj|;i<j}_(k)
the kth order statistic of the
( n over 2 )interpoint distancesk=(n/2+1 over 2). Optimised version.See:
Rousseeuw, P. J. & Croux C. Alternatives to the Median Absolute Deviation Journal of the American Statistical Association 1993, 88, 1273-1283 Croux, C. & Rousseeuw, P. J. Time-efficient algorithms for two highly robust estimators of scale Computational Statistics 1992, 1Parameters: - data (float array-like) – input data
- c (float) – scaling multiplyer (see background paper)
Returns: Qn (float).
-
StatisticalDiagrams.RobustStatistics.QnExplicit(data, c=2.2219)¶ Robust scale measure:
Qn = c*dn*{|xi-xj|;i<j}_(k)
the kth order statistic of the
( n over 2 )interpoint distancesk=(n/2+1 over 2). In this version the mathematical definition was directly translated into code. This is highly inefficient (time and memory) and should only be used for checks.See:
Rousseeuw, P. J. & Croux C. Alternatives to the Median Absolute Deviation Journal of the American Statistical Association 1993, 88, 1273-1283 Croux, C. & Rousseeuw, P. J. Time-efficient algorithms for two highly robust estimators of scale Computational Statistics 1992, 1Parameters: - data (float array-like) – input data
- c (float) – scaling multiplyer (see background paper)
Returns: Qn (float).
-
StatisticalDiagrams.RobustStatistics.Sdist(s1, s2, distFun)¶ Computes distance scale between to sets of samples based on Sn metric.
Parameters: - s1, s2 (float array-likes) – input datasets, same shape.
- distFun – distance function to be used
Returns: Median distance based on
-
StatisticalDiagrams.RobustStatistics.Sn(data)¶ Robust Scale measure:
Sn = 1.1926 lowmed(i=1,n)( highmed(j=1,n)(|xi - xj|) )
Optimised Version See: Rousseeuw, P. J. & Croux C. Alternatives to the Median Absolute Deviation Journal of the American Statistical Association 1993, 88, 1273-1283 Croux, C. & Rousseeuw, P. J. Time-efficient algorithms for two highly robust estimators of scale Computational Statistics 1992, 1
Parameters: data (float array-like) – input data Returns: Sn
-
StatisticalDiagrams.RobustStatistics.SnExplicit(data, c=1.1926)¶ Robust Scale measure:
Sn = 1.1926 med(i=1,n)( med(j=1,n)(|xi - xj|) )
In this version the mathematical definition was directly translated into code. This is highly inefficient (time and memory) and should only be used for checks. See: Rousseeuw, P. J. & Croux C. Alternatives to the Median Absolute Deviation Journal of the American Statistical Association 1993, 88, 1273-1283 Croux, C. & Rousseeuw, P. J. Time-efficient algorithms for two highly robust estimators of scale Computational Statistics 1992, 1 :Parameters: data (float array-like) – input data
Returns: Sn
-
StatisticalDiagrams.RobustStatistics.binomcoeff(n, k)¶ Binomial coefficient.
Parameters: - n (integer) – positive integer number
- k (integer) – positive integer number <= n
Returns: Binomial coefficient (integer).
-
StatisticalDiagrams.RobustStatistics.flatCompress(data)¶ Flattened and compressed (removing masekd values) representation of input data.
Parameters: data (array-like) – input data Returns: flattened and compressed version of input data.
-
StatisticalDiagrams.RobustStatistics.flatCompressSamples(s1, s2)¶ Flattened and compressed representation of two datasets using the combined mask of the two (by disjunction).
Parameters: - s1 (array-like) – first input dataset
- s2 (array-like) – second input dataset, same shape as first
Returns: Flattened and compressed representation of input datasets.
-
StatisticalDiagrams.RobustStatistics.unbiasedMAE(x, y)¶ Computes unbiased Median Absolute Error:
uMAE=med|xi-yi-med(xi)+med(yi)||
Parameters: x,y (float array-like) – datasets to compare, same shape Returns: Median bias (float).