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
Examples
importing numpy, and NP_Mixture_Smoother
>>> import numpy as np >>> from esda.mixture_smoothing import NP_Mixture_Smoothercreating 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)getSeed()getStepsize(mix_den, ht)mixalg()update(p, grid)vem(mix, p, grid)