In: Computer Science
Given a dataset of random numbers, use Python to calculate:
(a) Estimates for the sample mean and sample variance without using inbuilt functions.
(b) Suppose now that the standard deviation is known to be 0.25. Compute a 90% confidence interval for the population mean. (python libraries can be used to calculate the confidence interval)
Data:
8.91E+00 |
1.53E+01 |
5.98E+00 |
6.39E+00 |
1.54E+00 |
1.05E+01 |
1.87E+00 |
2.14E+00 |
6.50E+00 |
3.20E+00 |
3.10E+00 |
5.16E+00 |
6.04E-01 |
1.75E+00 |
1.27E+00 |
3.15E+00 |
5.09E+00 |
5.19E-01 |
5.23E+00 |
4.17E+00 |
2.34E+01 |
4.94E+00 |
8.85E+00 |
1.66E-01 |
6.38E+00 |
1.09E+00 |
2.02E+00 |
4.06E-02 |
2.44E+00 |
8.56E+00 |
# Putting data into a List in order to process it
data = [8.91E+00,1.53E+01,5.98E+00,6.39E+00,1.54E+00,1.05E+01,1.87E+00,2.14E+00,6.50E+00,3.20E+00,
3.10E+00,5.16E+00,6.04E-01,1.75E+00,1.27E+00,3.15E+00,5.09E+00,5.19E-01,5.23E+00,4.17E+00,
2.34E+01,4.94E+00,8.85E+00,1.66E-01,6.38E+00,1.09E+00,2.02E+00,4.06E-02,2.44E+00,8.56E+00]
# Get number of observations
N = len(data)
# Varaible required to calculate mean
sumOfData = 0
# Loop to calculate sum of all values
for x in data:
sumOfData+=x
# Formula to calulate mean
mean = sumOfData/N
sumForVar = 0
# Loop to store diffrences of number and mean
for x in range(N):
sumForVar+= ( (data[x]-mean)**2)
sampleVaraince = sumForVar/(N-1)
# To calculate confidence interval
# we use mean, Stadard deviation and condidence lebel 90
# The z* value for 90% is 1.645
# Taking required variables to calcualte
# Confidence intervals
Z_star = 1.645
stdDeviation = 0.25
N_root = N**(1/2)
# Formuala to calulate margin of error for confidence intervals
marginOfError = Z_star * (stdDeviation/N_root)
# Both Confidence intervals
CI_upperBound = mean + marginOfError
CI_lowerBound = mean - marginOfError
print("Lower Bound of condidence interval: ",CI_lowerBound)
print("Upper Bound of condidence interval: ",CI_upperBound)
print("Mean of the data: ",mean)
print("Varaiance of data :",sampleVaraince)
Screenshots of the code:
Screenshot of the output:
Explanation:
I hope, I'm clear with my answers. Please Upvote