Skip to content

Instantly share code, notes, and snippets.

View chaipi-chaya's full-sized avatar

Chaya Chaipitakporn chaipi-chaya

View GitHub Profile
@chaipi-chaya
chaipi-chaya / sampleSizeIncreaseLine.py
Last active October 23, 2019 18:41
Illustration with Python Central Limit Theorem | sample size increases the probability that sample mean is further from population mean than error
import numpy as np
import random
import matplotlib.pyplot as plt
# Step 1
## show that as the sample size increases the mean of sample is close to population mean
# build gamma distribution as population
shape, scale = 2., 2. # mean=4, std=2*sqrt(2)
mu = shape*scale # mean
s = np.random.gamma(shape, scale, 1000000)
@chaipi-chaya
chaipi-chaya / sampleSizeIncreaseDot.py
Last active October 23, 2019 18:40
Illustration with Python Central Limit Theorem | sample size increases the mean of sample is close to population mean
import numpy as np
import random
import matplotlib.pyplot as plt
# Step 1
## show that as the sample size increases the mean of sample is close to population mean
# build gamma distribution as population
shape, scale = 2., 2. # mean=4, std=2*sqrt(2)
s = np.random.gamma(shape, scale, 1000000)
@chaipi-chaya
chaipi-chaya / muandSigmaSampleMean.py
Last active October 23, 2019 18:30
Illustration with Python Central Limit Theorem | expected value and standard deviation of sample means
## expect value of sample
import numpy as np
# use last sampling
from diffSampleSize import meansample
# mean and standard deviation from population
shape, scale = 2., 2. # mean=4, std=2*sqrt(2)
sample = meansample[5]
# expected value of sample equal to expect value of population
print("expected value of sample:", np.mean(sample))
@chaipi-chaya
chaipi-chaya / diffSampleSize.py
Last active October 23, 2019 18:31
Illustration with Python Central Limit Theorem | sample with different sample size
import numpy as np
import random
import matplotlib.pyplot as plt
# build gamma distribution as population
shape, scale = 2., 2. # mean=4, std=2*sqrt(2)
s = np.random.gamma(shape, scale, 1000000)
# Step 1
## sample with different sample size
@chaipi-chaya
chaipi-chaya / standardize.py
Last active October 23, 2019 18:10
Illustration with Python Central Limit Theorem | standardize
## standardize part
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
# Step 1
# use last sampling
from diffNumSampling import meansample
sm = meansample[len(meansample)-1]
@chaipi-chaya
chaipi-chaya / Chebyshev’sInequality.py
Last active October 23, 2019 16:45
Illustration with Python: Chebyshev’s Inequality
import numpy as np
import random
import matplotlib.pyplot as plt
# Step 1
# create a population with a gamma distribution
shape, scale = 2., 2. # mean=4, std=2*sqrt(2)
mu = shape*scale # mean and standard deviation
sigma = scale*np.sqrt(shape)
s = np.random.gamma(shape, scale, 1000000)