Question: Exercise - 1 : Import all the libraries - numpy, pandas, matplotlib, and statsmodels so that we do not have to worry about importing the
Exercise: 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.
Point
:
#GIVE YOUR ANSWER FOR EXERCISE IN THIS CELL
import numpy as np pandas as pd
END OF EXERCISE
Confidence Intervals
Exercise: A sample dataset on the mother baby pairs are given in the baby.csv file. The objective of this exercise is to build a and a confidence interval to estimate the proportion percentage of maternal mothers who smoked in the unknown population. Specific tasks for this exercise are given below.
Points
Task: Read the baby.csv file and store it in a variable named df Display the first rows of the dataframe df
:
#GIVE YOUR ANSWER FOR TASK IN THIS CELL
Task: Write a function named maternalsmokersproportion 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 propmaternalsmokers and print it to the output.
Note: Inside the function, you can use the countnonzero 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: 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 countnonzero function.
:
#GIVE YOUR ANSWER FOR TASK IN THIS CELL
Task: In this task, pick a resample dataframe from the sample dataset and store it in a variable named resample. Pass resample to the function maternalsmokersproportion that will return the proportion of maternal smokers in the resample. Store the returned value of proportion of maternal smokers in a variable named resamplepropmaternalsmokers and print it to the output.
:
#GIVE YOUR ANSWER FOR TASK IN THIS CELL
Task: Repeat task for resamples and append the values resamplepropmaternalsmokers that you get for each of the resamples to an empty list named bootstraps. Print the length of boostraps to the output.
:
#GIVE YOUR ANSWER FOR TASK IN THIS CELL
Task: Plot a histogram of the statistical estimates of proportion contained in the array named bootstraps. Also, the plot must display appropriate xlabel, ylabel, and title.
:
#GIVE YOUR ANSWER FOR TASK IN THIS CELL
Task: You have to find out the middle of the resampled proportion values. To do that, in this task, you have to find out the left most end of the middle and right most end of the middle Store the values in variables named left and right Print left and right to the output.
:
#GIVE YOUR ANSWER FOR TASK IN THIS CELL
Task: You have to find out the middle of the resampled proportion values. To do that, in this task, you have to find out the left most end of the middle and right most end of the middle Store the values in variables named left and right Print left and right to the output.
:
#GIVE YOUR ANSWER FOR TASK IN THIS CELL
Task: Repeat task but this time, the plot must also display the middle interval and the middle interval of the proportion values. Make sure you include a label for the CI and CI
:
#GIVE YOUR ANSWER FOR TASK IN THIS CELL
Task: Give your inference for both confidence interval and confidence interval. In other words, what is the estimated confidence interval of proportion of maternal smokers in the population and the estimated 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 IN THIS CELL
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
