python-igraph manual

For using igraph from Python

   Home       Trees       Indices       Help   
Package igraph :: Module statistics
[hide private]

Module statistics

source code

Statistics related stuff in igraph


License: Copyright (C) 2006-2012 Tamas Nepusz <ntamas@gmail.com> Pázmány Péter sétány 1/a, 1117 Budapest, Hungary This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Classes [hide private]
  FittedPowerLaw
Result of fitting a power-law to a vector of samples
  Histogram
Generic histogram class for real numbers
  RunningMean
Running mean calculator.
Functions [hide private]
 
mean(xs)
Returns the mean of an iterable.
source code
 
median(xs, sort=True)
Returns the median of an unsorted or sorted numeric vector.
source code
 
percentile(xs, p=(25, 50, 75), sort=True)
Returns the pth percentile of an unsorted or sorted numeric vector.
source code
 
power_law_fit(data, xmin=None, method='auto', return_alpha_only=False)
Fitting a power-law distribution to empirical data
source code
 
quantile(xs, q=(0.25, 0.5, 0.75), sort=True)
Returns the qth quantile of an unsorted or sorted numeric vector.
source code
 
sd(xs)
Returns the standard deviation of an iterable.
source code
 
var(xs)
Returns the variance of an iterable.
source code
Variables [hide private]
  __package__ = 'igraph'

Imports: math


Function Details [hide private]

mean(xs)

source code 

Returns the mean of an iterable.

Example:

>>> mean([1, 4, 7, 11])
5.75
Parameters:
  • xs - an iterable yielding numbers.
Returns:
the mean of the numbers provided by the iterable.

See Also: RunningMean() if you also need the variance or the standard deviation

median(xs, sort=True)

source code 

Returns the median of an unsorted or sorted numeric vector.

Parameters:
  • xs - the vector itself.
  • sort - whether to sort the vector. If you know that the vector is sorted already, pass False here.
Returns:
the median, which will always be a float, even if the vector contained integers originally.

percentile(xs, p=(25, 50, 75), sort=True)

source code 

Returns the pth percentile of an unsorted or sorted numeric vector.

This is equivalent to calling quantile(xs, p/100.0); see quantile for more details on the calculation.

Example:

>>> round(percentile([15, 20, 40, 35, 50], 40), 2)
26.0
>>> for perc in percentile([15, 20, 40, 35, 50], (0, 25, 50, 75, 100)):
...     print "%.2f" % perc
...
15.00
17.50
35.00
45.00
50.00
Parameters:
  • xs - the vector itself.
  • p - the percentile we are looking for. It may also be a list if you want to calculate multiple quantiles with a single call. The default value calculates the 25th, 50th and 75th percentile.
  • sort - whether to sort the vector. If you know that the vector is sorted already, pass False here.
Returns:
the pth percentile, which will always be a float, even if the vector contained integers originally. If p is a list, the result will also be a list containing the percentiles for each item in the list.

power_law_fit(data, xmin=None, method='auto', return_alpha_only=False)

source code 

Fitting a power-law distribution to empirical data

Parameters:
  • data - the data to fit, a list containing integer values
  • xmin - the lower bound for fitting the power-law. If None, the optimal xmin value will be estimated as well. Zero means that the smallest possible xmin value will be used.
  • method - the fitting method to use. The following methods are implemented so far:
    • continuous, hill: exact maximum likelihood estimation when the input data comes from a continuous scale. This is known as the Hill estimator. The statistical error of this estimator is (alpha-1) / sqrt(n), where alpha is the estimated exponent and n is the number of data points above xmin. The estimator is known to exhibit a small finite sample-size bias of order O(n^-1), which is small when n > 100. igraph will try to compensate for the finite sample size if n is small.
    • discrete: exact maximum likelihood estimation when the input comes from a discrete scale (see Clauset et al among the references).
    • auto: exact maximum likelihood estimation where the continuous method is used if the input vector contains at least one fractional value and the discrete method is used if the input vector contains integers only.
Returns:
a FittedPowerLaw object. The fitted xmin value and the power-law exponent can be queried from the xmin and alpha properties of the returned object.
Reference:
  • MEJ Newman: Power laws, Pareto distributions and Zipf's law. Contemporary Physics 46, 323-351 (2005)
  • A Clauset, CR Shalizi, MEJ Newman: Power-law distributions in empirical data. E-print (2007). arXiv:0706.1062

quantile(xs, q=(0.25, 0.5, 0.75), sort=True)

source code 

Returns the qth quantile of an unsorted or sorted numeric vector.

There are a number of different ways to calculate the sample quantile. The method implemented by igraph is the one recommended by NIST. First we calculate a rank n as q(N+1), where N is the number of items in xs, then we split n into its integer component k and decimal component d. If k <= 1, we return the first element; if k >= N, we return the last element, otherwise we return the linear interpolation between xs[k-1] and xs[k] using a factor d.

Example:

>>> round(quantile([15, 20, 40, 35, 50], 0.4), 2)
26.0
Parameters:
  • xs - the vector itself.
  • q - the quantile we are looking for. It may also be a list if you want to calculate multiple quantiles with a single call. The default value calculates the 25th, 50th and 75th percentile.
  • sort - whether to sort the vector. If you know that the vector is sorted already, pass False here.
Returns:
the qth quantile, which will always be a float, even if the vector contained integers originally. If q is a list, the result will also be a list containing the quantiles for each item in the list.

sd(xs)

source code 

Returns the standard deviation of an iterable.

Example:

>>> sd([1, 4, 7, 11])       #doctest:+ELLIPSIS
4.2720...
Parameters:
  • xs - an iterable yielding numbers.
Returns:
the standard deviation of the numbers provided by the iterable.

See Also: RunningMean() if you also need the mean

var(xs)

source code 

Returns the variance of an iterable.

Example:

>>> var([1, 4, 8, 11])            #doctest:+ELLIPSIS
19.333333...
Parameters:
  • xs - an iterable yielding numbers.
Returns:
the variance of the numbers provided by the iterable.

See Also: RunningMean() if you also need the mean


   Home       Trees       Indices       Help