コード例 #1
0
import my_stat_functions as my_stats

MU = 35.0 #hours
SIGMA = 5.5 #hours
SAMPLE_SIZE = 25 #batteries

print('a. What can you say about the shape of the distribution of the sample mean?')
print('Without calculating anything yet, I would say that the distribution of the sample \
    mean will have a shape resembling a normal distribution. The Central Limit Theorom allows \
    for this conclusion.')

print('\nb. What is the standard error of the distribution of the sample mean?')
print(f'The standard error of the distribution of the sample mean is {my_stats.std_error_of_mean(SIGMA, SAMPLE_SIZE):.4f}')

print('\nc. What proportion of the samples will have a mean useful life of more than 36 hours?')
z_c = my_stats.z_value_known_sigma(36, MU, SIGMA, SAMPLE_SIZE)
area_c = .3186
p_c = .5000 - area_c
print('Because the sample mean is higher than the population mean and we are looking \n\
for the proportion above the sample mean we subtract it\'s area from .5000 to find the \n\
proportion we are interested in.')
print(f'z = {z_c:.4f} \np = .5000 - {area_c} = { p_c }')

print('\nd. What proportion of the samples will have a mean useful life greater than 34.5 hours?')
z_d = my_stats.z_value_known_sigma(34.5, MU, SIGMA, SAMPLE_SIZE)
area_d = .1736
p_d = .5000 + area_d
print('Because the sample mean is lower than the population mean and we are looking \n\
for the proportion above the sample mean we add it\'s area to .5000 to find the \n\
proportion we are interested in.')
print(f'z = {z_d:.4f} \np = .5000 + {area_d} = { p_d }')
コード例 #2
0
'''
Recent studies indicate that the typical 50-year-old woman spends 
$350 per year for personal-care products. The distribution of the 
amounts spent follows a normal distribution with a standard deviation 
of $45 per year. We select a random sample of 40 women. The mean amount 
spent for those sampled is $335. 

What is the likelihood of finding a sample mean this large or larger 
from the specified population?
'''
import my_stat_functions as my_stats

MU = 350
SIGMA = 45
SAMPLE_SIZE = 40
X_BAR = 335

z = my_stats.z_value_known_sigma(X_BAR, MU, SIGMA, SAMPLE_SIZE)
print(f'z = {z:.2f}')
area = .4826
print(
    f'Because the sample mean (X_BAR) is less than the population mean (MU), we add {area} to .5000 to get the area for z-values greater than {z:2f}.'
)
print(f'{area} + .5000 = {area + .5000:.4f}')
コード例 #3
0
'''
import my_stat_functions as my_stats
MU = 6.5  #pair shoes
SIGMA = 2.1  #pair shoes
SAMPLE_SIZE = 81  #customers
X_BAR_A = 6
X_BAR_B = 7

print('a. What is the standard error of the mean in this experiment?')
std_error = my_stats.std_error_of_mean(SIGMA, SAMPLE_SIZE)
print(f'{std_error:.4f}')

print(
    '\nb. What is the probability that the sample mean is between six and seven pairs of sports shoes?'
)
z_a = my_stats.z_value_known_sigma(X_BAR_A, MU, SIGMA, SAMPLE_SIZE)
print(f'z_a = {z_a:.2f}')
area_a = .4838

z_b = my_stats.z_value_known_sigma(X_BAR_B, MU, SIGMA, SAMPLE_SIZE)
print(f'z_b = {z_b:.2f}')
area_b = .4838

print(
    f'Because the sample means (X_BAR_A = {X_BAR_A} and X_BAR_B = {X_BAR_B}) are on opposite sides of the \
population mean (MU {MU}), we add them to get the area for z-values between them.'
)
print(f'{area_a} + {area_b} = { area_a + area_b:.4f}')

print(
    '\nc. What is the probability that the difference between the sample mean and the population mean is less than 0.25 pair?'