macroeco.models.power_law

macroeco.models.power_law = <macroeco.models._curves.power_law_gen object at 0x10884cf90>

A power-law function

\[y = c x^z\]

or equivalently

\[\log(y) = \log(c) + z \log(x)\]

Stemming from the log form, c is often known as the intercept and z as the slope of the power law.

Parameters:

x : iterable

Independent variable

y_obs : iterable

Dependent variable (values observed at x)

params_start : iterable

Optional start values for all parameters. Default 1.

c, z :

Parameters: Log-log slope and intercept

Examples

>>> # Specify a classic power law with z = 0.25
>>> import macroeco.models as md
>>> areas = [1, 0.5, 0.25, 0.125]
>>> c = 20  # Number of species at the base scale
>>> z = 0.25 # Slope of the power law
>>> # Get the species richness predictions of the power law
>>> res = md.power_law.vals(areas, c, z)
>>> res
array([ 20.        ,  16.81792831,  14.14213562,  11.89207115])
>>> # Fit the power law using least squares
>>> md.power_law.fit_lsq(areas, res)
(20.0, 0.25000000000000006)

Methods

vals(x, parameters) Dependent variable y given independent variable x and curve parameters
fit_lsq(x, y_obs, params_start=None) Least squares fit of parameters given data