esda.NP_Mixture_Smoother

class esda.NP_Mixture_Smoother(e, b, k=50, acc=1e-07, numiter=5000, limit=0.01)[source]

Empirical Bayesian Rate Smoother Using Mixture Prior Distributions It goes through 1) defining an initial set of subpopulations, 2) VEM algorithm to determine the number of major subpopulations, 3) EM algorithm, 4) combining simialr subpopulations, and 5) estimating EB rates from a mixture of prior distributions from subpopulation models.

Parameters:
e : array-like

event variable measured across n spatial units

b : array-like

population at risk variable measured across n spatial units

k : integer

a seed number to specify the number of subpopulations

acc : float

convergence criterion; VEM and EM loops stop when the increase of log likelihood is less than acc

numiter : integer

the maximum number of iterations for VEM and EM loops

limit : float

a parameter to cotrol the limit for combing subpopulation models

e[source]

same as e in parameters

Type:

array

b[source]

same as b in parameters

Type:

array

n[source]

the number of observations

Type:

integer

w[source]

a global weight value, 1 devided by n

Type:

float

k[source]

the number of subpopulations

Type:

integer

acc[source]

same as acc in parameters

Type:

float

numiter[source]

same as numiter in parameters

Type:

integer

limit[source]

same as limit in parameters

Type:

float

p[source]

(k, 1), the proportions of individual subpopulations

Type:

array

t[source]

(k, 1), prior risks of individual subpopulations

Type:

array

r[source]

(n, 1), estimated rate values

Type:

array

category[source]

(n, 1), indices of subpopulations to which each observation belongs

Type:

array

Examples

importing numpy, and NP_Mixture_Smoother

>>> import numpy as np
>>> from esda.mixture_smoothing import NP_Mixture_Smoother

creating an arrary including event values

>>> e = np.array([10, 5, 12, 20])

creating an array including population-at-risk values

>>> b = np.array([100, 150, 80, 200])

applying non-parametric mixture smoothing to e and b

>>> mixture = NP_Mixture_Smoother(e, b)

extracting the smoothed rates through the property r of the NP_Mixture_Smoother instance

>>> mixture.r
array([0.10982278, 0.03445531, 0.11018404, 0.11018604])

Checking the subpopulations to which each observation belongs

>>> mixture.category
array([1, 0, 1, 1])

computing an initial set of prior distributions for the subpopulations

>>> mixture.getSeed()
(array([0.5, 0.5]), array([0.03333333, 0.15      ]))

applying the mixture algorithm

>>> mixture.mixalg()
{'accuracy': 1.0, 'k': 1, 'p': array([1.]), 'grid': array([11.27659574]), 'gradient': array([0.]), 'mix_den': array([0., 0., 0., 0.])}

estimating empirical Bayesian smoothed rates

>>> mixture.getRateEstimates()
(array([0.0911574, 0.0911574, 0.0911574, 0.0911574]), array([1, 1, 1, 1]))

Methods

combine(res)

em(nstep, grid, p)

getGradient(mix, p)

getLikelihood(mix_den)

getMaxGradient(gradient)

getMinGradient(gradient, p)

getMixedProb(grid)

getRateEstimates()

getSeed()

getStepsize(mix_den, ht)

mixalg()

update(p, grid)

vem(mix, p, grid)

combine(res)[source]
em(nstep, grid, p)[source]
getGradient(mix, p)[source]
getLikelihood(mix_den)[source]
getMaxGradient(gradient)[source]
getMinGradient(gradient, p)[source]
getMixedProb(grid)[source]
getRateEstimates()[source]
getSeed()[source]
getStepsize(mix_den, ht)[source]
mixalg()[source]
update(p, grid)[source]
vem(mix, p, grid)[source]