Question: Exercise - 1 : Import all the libraries - numpy, pandas, matplotlib, and statsmodels so that we do not have to worry about importing the

Exercise-1: Import all the libraries - numpy, pandas, matplotlib, and statsmodels so that we do not have to worry about importing the libraries later on in this assignment.
(1 Point)
[]:
#GIVE YOUR ANSWER FOR EXERCISE-1 IN THIS CELL
import numpy as np, pandas as pd
-------------------END OF EXERCISE-1--------------------------
1) Confidence Intervals
Exercise-2: A sample dataset on the 1,174 mother baby pairs are given in the baby.csv file. The objective of this exercise is to build a 95% and a 85% confidence interval to estimate the proportion (percentage) of maternal mothers who smoked in the unknown population. Specific tasks for this exercise are given below.
(30 Points)
Task-1: Read the baby.csv file and store it in a variable named df. Display the first 5 rows of the dataframe df.
[]:
#GIVE YOUR ANSWER FOR TASK-1 IN THIS CELL
Task-2: Write a function named maternal_smokers_proportion that will compute and return the proportion of maternal smokers. The function must take one argument named n that will receive the dataframe df. Once you finish writing the function, call the function and pass the dataframe df to it. Store the returned proportion value in a variable named prop_maternalsmokers and print it to the output.
Note-1: Inside the function, you can use the count_nonzero() function to first count the number of maternal smokers in the sample dataset and then the shape method in Pandas library to get the total number of maternal mothers in the sample dataset. Do not hardcode the number of mothers in the dataset.
Note-2: The number of maternal smokers in the sample dataset can also be found using different other functions in Pandas library. You can use them too instead of count_nonzero() function.
[]:
#GIVE YOUR ANSWER FOR TASK-2 IN THIS CELL
Task-3: In this task, pick a resample dataframe from the sample dataset and store it in a variable named resample. Pass resample to the function maternal_smokers_proportion that will return the proportion of maternal smokers in the resample. Store the returned value of proportion of maternal smokers in a variable named resample_prop_maternalsmokers and print it to the output.
[]:
#GIVE YOUR ANSWER FOR TASK-3 IN THIS CELL
Task-4: Repeat task-3 for 10,000 resamples and append the values resample_prop_maternalsmokers that you get for each of the 10,000 resamples to an empty list named bootstraps. Print the length of boostraps to the output.
[]:
#GIVE YOUR ANSWER FOR TASK-4 IN THIS CELL
Task-5: Plot a histogram of the statistical estimates of proportion contained in the array named bootstraps. Also, the plot must display appropriate x-label, y-label, and title.
[]:
#GIVE YOUR ANSWER FOR TASK-5 IN THIS CELL
Task-6: You have to find out the middle 95% of the resampled proportion values. To do that, in this task, you have to find out the left most end of the middle 95% and right most end of the middle 95%. Store the values in variables named left_95 and right_95. Print left_95 and right_95 to the output.
[]:
#GIVE YOUR ANSWER FOR TASK-6 IN THIS CELL
Task-7: You have to find out the middle 85% of the resampled proportion values. To do that, in this task, you have to find out the left most end of the middle 85% and right most end of the middle 85%. Store the values in variables named left_85 and right_85. Print left_85 and right_85 to the output.
[]:
#GIVE YOUR ANSWER FOR TASK-7 IN THIS CELL
Task-8: Repeat task-5 but this time, the plot must also display the middle 95% interval and the middle 85% interval of the proportion values. Make sure you include a label for the 95% CI and 85% CI.
[]:
#GIVE YOUR ANSWER FOR TASK-8 IN THIS CELL
Task-9: Give your inference for both 95% confidence interval and 85% confidence interval. In other words, what is the estimated 95% confidence interval of proportion of maternal smokers in the population and the estimated 85% confidence interval of proportion of maternal smokers in the population? Make sure you specify the sample size in the inference based on which you estimated the intervals.
GIVE YOUR ANSWER FOR TASK-9 IN THIS CELL

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!