def test_mean_var(self): poisson_mean, poisson_var = poisson.mean(12), poisson.var(12) zipoisson_mean = sm.distributions.zipoisson.mean(12, 0) zipoisson_var = sm.distributions.zipoisson.var(12, 0) assert_allclose(poisson_mean, zipoisson_mean, rtol=1e-10) assert_allclose(poisson_var, zipoisson_var, rtol=1e-10) m = np.array([1, 5, 10]) poisson_mean, poisson_var = poisson.mean(m), poisson.var(m) zipoisson_mean = sm.distributions.zipoisson._mean(m, 0) zipoisson_var = sm.distributions.zipoisson._var(m, 0.0) assert_allclose(poisson_mean, zipoisson_mean, rtol=1e-10) assert_allclose(poisson_var, zipoisson_var, rtol=1e-10)
def test_mean_var(self): # compare with Poisson special case m = np.array([1, 5, 10]) poisson_mean, poisson_var = poisson.mean(m), poisson.var(m) zigenpoisson_mean = sm.distributions.zigenpoisson._mean(m, 0, 1, 0) zigenpoisson_var = sm.distributions.zigenpoisson._var(m, 0.0, 1, 0) assert_allclose(poisson_mean, zigenpoisson_mean, rtol=1e-10) assert_allclose(poisson_var, zigenpoisson_var, rtol=1e-10)
def test_substitutions_changes(self): """Test that substitions occur at the expected rate.""" cfg = AppSettings() reps = 1000 deltas = [] for _ in range(0, reps): seq = "a" * 100 dna = Chromosome(seq) dna.substitutions() deltas.append(sum(1 for a, b in zip(seq, dna.sequence) if a != b)) # Expand the conf_99 to compensate for repeated mutations in the same place expected_delta = cfg.genetics.mutation_rate * 100 * \ (1 - 1/len(Chromosome.nucleotides())) # Because there is a little slop around synonymous substitions I multiply # the confidence by 10 just to limit the number of failing tests. conf_99 = ((poisson.var(cfg.genetics.mutation_rate * 100) / 1000) **(1 / 2)) * 10 observed_delta = sum(deltas) / reps assert (expected_delta - conf_99) < observed_delta < (expected_delta + conf_99)
def var(self, dist): return poisson.var(*self._get_params(dist))
def var(self, n, p): var = poisson.var(self, n, p) return var
from scipy.stats import poisson import numpy as np # Assume the number of typo errors on a single page of a book follows # Poisson distribution with parameter 1/3. Calculate the probability # that on one page there are # no typos (pmf(0,1/3) = 0.7165313105737893) # exactly two typos = (pmf(0,1/3) = 0.03980729503187717) k = 1 mu = 2.5 expect = poisson.expect(args=(mu,), loc=0) mean = poisson.mean(mu) var = poisson.var(mu) sigma = poisson.std(mu) pmf = poisson.pmf(k, mu, loc=0) cdf = poisson.cdf(k, mu, loc=0) e_x_squared = mu**2 + mu print('expected = ', expect) print('mean = ', mean) print('variance = ', var) print('std. dev. = ',sigma) print('pmf = ', pmf) print('cdf = ', cdf) print('E[X]^2 = ', e_x_squared)
def test_mean_var(self): poisson_mean, poisson_var = poisson.mean(12), poisson.var(12) zipoisson_mean = sm.distributions.zipoisson.mean(12, 0) zipoisson_var = sm.distributions.zipoisson.mean(12, 0) assert_allclose(poisson_mean, zipoisson_mean, rtol=1e-10) assert_allclose(poisson_var, zipoisson_var, rtol=1e-10)