Question

In: Computer Science

Given a dataset of random numbers, use Python to calculate: (a) Estimates for the sample mean...

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

Solutions

Expert Solution

# 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:

  • At first, I have created a list of all the values that you have given in the question.
  • After that, the size of the data is calculated by using len function of Python.
  • Then, a loop will calculate the sum of all values and after that mean is calculated by dividing the size of data by the sum of data.
  • Then, a variable for the sum of all variance of the values is defined. A loop will calculate the difference of the mean and the values and it will be added to a variable.
  • Then sample variance is calculated by using this variable and size of data.
  • For (b) part of the question, we will use the mean, standard deviation that is given in the question, and Z* value of 90% confidence.
  • After assigning all values to the required variables, the margin of error is calculated.
  • This margin will be used to get upper bound and lower bound of confidence intervals.
  • After subtracting and addition of the margin of error we have our required confidence intervals with 90% confidence value.

I hope, I'm clear with my answers. Please Upvote


Related Solutions

Please use Python 3 3). Write a function that writes a series of random numbers to...
Please use Python 3 3). Write a function that writes a series of random numbers to a text file named ‘random_number.txt’. Each random number should be in the range of 1 through 500. The function should let the user specify how many random numbers the file will hold. Then write another function that reads the random numbers from the ‘random_number.txt’ file, displays the numbers, and then displays the total of the numbers and the number of random numbers read from...
The following numbers constitute a random sample from a normal distribution with an unknown mean and...
The following numbers constitute a random sample from a normal distribution with an unknown mean and unknown variance σ 2 1 : 15.0 19.1 16.6 20.4 13.5 (a) Test at the 5% significance level H0 : µ = 15 against Ha : µ > 15. Again, do the problem in two ways- first by obtaining the rejection region and second, by using the p-value. (b) Suppose we have another random sample from a normal distribution with an unknown mean and...
Use Python to plot poisson process for time interval [0,50] that generate 50 random numbers.
Use Python to plot poisson process for time interval [0,50] that generate 50 random numbers.
A sample mean, sample standard deviation, and sample size are given. Use the one mean t-test...
A sample mean, sample standard deviation, and sample size are given. Use the one mean t-test to perform the required hypothesis test about the mean M of the population from which the sample was drawn. Use the P- value approach. Also asses the strength of the evidence against the null hypothesis. Mean of the sample= 226,450 ; S= 11,500 ; n= 23 ; mean of the population = 220, 000 ; Ha : M>220,000 ; alpha = 0.01 . 2)....
Use the Law of large numbers to find the mean of continuous random variable. and Interpret...
Use the Law of large numbers to find the mean of continuous random variable. and Interpret that mean.
You are given the sample mean and the sample standard deviation. Use this information to construct...
You are given the sample mean and the sample standard deviation. Use this information to construct the​ 90% and​ 95% confidence intervals for the population mean. Which interval is​ wider? If​ convenient, use technology to construct the confidence intervals. A random sample of 4848 ​eight-ounce servings of different juice drinks has a mean of 88.688.6 calories and a standard deviation of 43.543.5 calories. The​ 90% confidence interval is left parenthesis nothing comma nothing right parenthesis .,. ​(Round to one decimal...
Use a random number generator to produce 1000 uniformly distributed numbers with a mean of 10, a
Use a random number generator to produce 1000 uniformly distributed numbers with a mean of 10, a minimum of 2, and a maximum of 18. Obtain the mean and the histogram of these numbers, and discuss whether they appear uniformly distributed with the desired mean.
Use a random number generator to produce 1000 normally distributed numbers with a mean of 20
Use a random number generator to produce 1000 normally distributed numbers with a mean of 20 and a variance of 4. Obtain the mean, variance, and histogram of these numbers, and discuss whether they appear normally distributed with the desired mean and variance.
Given a random sample of size 16 from a normally distributed population with a mean of...
Given a random sample of size 16 from a normally distributed population with a mean of 100 and standard deviation of 24, find P(x bar≤90)
in PYTHON given a specific text file containing a list of numbers on each line (numbers...
in PYTHON given a specific text file containing a list of numbers on each line (numbers on each line are different) write results to a new file after the following tasks are performed: Get rid of each line of numbers that is not 8 characters long Get rid of lines that don't begin with (478, 932, 188, 642, 093)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT