Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 def mean(self, dist):
     return poisson.mean(*self._get_params(dist))
Ejemplo n.º 4
0
#Exercise 3 -- Cuberschi Lucian
#(Random variables, implementation)

#Suppose you measure the temperature 10 consecutive days with a thermometer that has a small random error.

# 1.What is the mean temperature, knowing that the mean error is +1°C and the measurements are those in the variable Y below.
# 2.You have a second thermometer with a Fahrenheit scale ( 𝑇(°𝐹)=𝑇(°𝐶)×1.8+32 ).
# The variance of the measurements of this thermometer (in Fahrenheit) is 8. Is this higher or lower than the variance shown by the first one?

import math
from scipy.stats import poisson

C = [21, 20, 22, 23, 20, 19, 19, 18, 19, 20]
mean = sum(C) / len(C) - 1
print('mean 1 is: ', poisson.mean(mean))

C1 = [x * 18 / 10 + 32 - (1 * 18 / 10 + 32) for x in C]
meanF = sum(C1) / len(C1)
sd = 0.0
for i in C1:
    sd = sd + (i - meanF) * (i - meanF)  #sum of x - mean(x)
sd = math.sqrt(sd / 9)  #sd formula
varC = sd * sd
print('varC is: ', varC)
varF = 8
if varF > varC:
    print('VarF higher then VarC')
else:
    print('VarF lower then VarC')
Ejemplo n.º 5
0
 def mean(self, n, p):
     mu = poisson.mean(self, n, p)
     return mu
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
 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)