diff --git a/your-code/.ipynb_checkpoints/main-checkpoint.ipynb b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb
new file mode 100644
index 0000000..83e7fc4
--- /dev/null
+++ b/your-code/.ipynb_checkpoints/main-checkpoint.ipynb
@@ -0,0 +1,403 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Before your start:\n",
+ "- Read the README.md file\n",
+ "- Comment as much as you can and use the resources (README.md file)\n",
+ "- Happy learning!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# import numpy and pandas\n",
+ "\n",
+ "import numpy as np\n",
+ "import pandas as pd"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 1 - Exploring the Data\n",
+ "\n",
+ "In this challenge, we will examine all salaries of employees of the City of Chicago. We will start by loading the dataset and examining its contents."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "db = pd.read_csv(\"Current_Employee_Names__Salaries__and_Position_Titles.csv\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Examine the `salaries` dataset using the `head` function below."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Name | \n",
+ " Job Titles | \n",
+ " Department | \n",
+ " Full or Part-Time | \n",
+ " Salary or Hourly | \n",
+ " Typical Hours | \n",
+ " Annual Salary | \n",
+ " Hourly Rate | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " AARON, JEFFERY M | \n",
+ " SERGEANT | \n",
+ " POLICE | \n",
+ " F | \n",
+ " Salary | \n",
+ " NaN | \n",
+ " 101442.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " AARON, KARINA | \n",
+ " POLICE OFFICER (ASSIGNED AS DETECTIVE) | \n",
+ " POLICE | \n",
+ " F | \n",
+ " Salary | \n",
+ " NaN | \n",
+ " 94122.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " AARON, KIMBERLEI R | \n",
+ " CHIEF CONTRACT EXPEDITER | \n",
+ " GENERAL SERVICES | \n",
+ " F | \n",
+ " Salary | \n",
+ " NaN | \n",
+ " 101592.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " ABAD JR, VICENTE M | \n",
+ " CIVIL ENGINEER IV | \n",
+ " WATER MGMNT | \n",
+ " F | \n",
+ " Salary | \n",
+ " NaN | \n",
+ " 110064.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " ABASCAL, REECE E | \n",
+ " TRAFFIC CONTROL AIDE-HOURLY | \n",
+ " OEMC | \n",
+ " P | \n",
+ " Hourly | \n",
+ " 20.0 | \n",
+ " NaN | \n",
+ " 19.86 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Name Job Titles \\\n",
+ "0 AARON, JEFFERY M SERGEANT \n",
+ "1 AARON, KARINA POLICE OFFICER (ASSIGNED AS DETECTIVE) \n",
+ "2 AARON, KIMBERLEI R CHIEF CONTRACT EXPEDITER \n",
+ "3 ABAD JR, VICENTE M CIVIL ENGINEER IV \n",
+ "4 ABASCAL, REECE E TRAFFIC CONTROL AIDE-HOURLY \n",
+ "\n",
+ " Department Full or Part-Time Salary or Hourly Typical Hours \\\n",
+ "0 POLICE F Salary NaN \n",
+ "1 POLICE F Salary NaN \n",
+ "2 GENERAL SERVICES F Salary NaN \n",
+ "3 WATER MGMNT F Salary NaN \n",
+ "4 OEMC P Hourly 20.0 \n",
+ "\n",
+ " Annual Salary Hourly Rate \n",
+ "0 101442.0 NaN \n",
+ "1 94122.0 NaN \n",
+ "2 101592.0 NaN \n",
+ "3 110064.0 NaN \n",
+ "4 NaN 19.86 "
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "db.head()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We see from looking at the `head` function that there is quite a bit of missing data. Let's examine how much missing data is in each column. Produce this output in the cell below"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's also look at the count of hourly vs. salaried employees. Write the code in the cell below"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "What this information indicates is that the table contains information about two types of employees - salaried and hourly. Some columns apply only to one type of employee while other columns only apply to another kind. This is why there are so many missing values. Therefore, we will not do anything to handle the missing values."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "There are different departments in the city. List all departments and the count of employees in each department."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 2 - Hypothesis Tests\n",
+ "\n",
+ "In this section of the lab, we will test whether the hourly wage of all hourly workers is significantly different from $30/hr. Import the correct one sample test function from scipy and perform the hypothesis test for a 95% two sided confidence interval."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We are also curious about salaries in the police force. The chief of police in Chicago claimed in a press briefing that salaries this year are higher than last year's mean of $86000/year a year for all salaried employees. Test this one sided hypothesis using a 95% confidence interval.\n",
+ "\n",
+ "Hint: A one tailed test has a p-value that is half of the two tailed p-value. If our hypothesis is greater than, then to reject, the test statistic must also be positive."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Using the `crosstab` function, find the department that has the most hourly workers. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The workers from the department with the most hourly workers have complained that their hourly wage is less than $35/hour. Using a one sample t-test, test this one-sided hypothesis at the 95% confidence level."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 3: To practice - Constructing Confidence Intervals\n",
+ "\n",
+ "While testing our hypothesis is a great way to gather empirical evidence for accepting or rejecting the hypothesis, another way to gather evidence is by creating a confidence interval. A confidence interval gives us information about the true mean of the population. So for a 95% confidence interval, we are 95% sure that the mean of the population is within the confidence interval. \n",
+ ").\n",
+ "\n",
+ "To read more about confidence intervals, click [here](https://en.wikipedia.org/wiki/Confidence_interval).\n",
+ "\n",
+ "\n",
+ "In the cell below, we will construct a 95% confidence interval for the mean hourly wage of all hourly workers. \n",
+ "\n",
+ "The confidence interval is computed in SciPy using the `t.interval` function. You can read more about this function [here](https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.t.html).\n",
+ "\n",
+ "To compute the confidence interval of the hourly wage, use the 0.95 for the confidence level, number of rows - 1 for degrees of freedom, the mean of the sample for the location parameter and the standard error for the scale. The standard error can be computed using [this](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.sem.html) function in SciPy."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now construct the 95% confidence interval for all salaried employeed in the police in the cell below."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Bonus Challenge - Hypothesis Tests of Proportions\n",
+ "\n",
+ "Another type of one sample test is a hypothesis test of proportions. In this test, we examine whether the proportion of a group in our sample is significantly different than a fraction. \n",
+ "\n",
+ "You can read more about one sample proportion tests [here](http://sphweb.bumc.bu.edu/otlt/MPH-Modules/BS/SAS/SAS6-CategoricalData/SAS6-CategoricalData2.html).\n",
+ "\n",
+ "In the cell below, use the `proportions_ztest` function from `statsmodels` to perform a hypothesis test that will determine whether the number of hourly workers in the City of Chicago is significantly different from 25% at the 95% confidence level."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.10.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/your-code/main.ipynb b/your-code/main.ipynb
index b2b6f8d..d318ce4 100644
--- a/your-code/main.ipynb
+++ b/your-code/main.ipynb
@@ -1,279 +1,917 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Before your start:\n",
- "- Read the README.md file\n",
- "- Comment as much as you can and use the resources (README.md file)\n",
- "- Happy learning!"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# import numpy and pandas\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Challenge 1 - Exploring the Data\n",
- "\n",
- "In this challenge, we will examine all salaries of employees of the City of Chicago. We will start by loading the dataset and examining its contents."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Examine the `salaries` dataset using the `head` function below."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "We see from looking at the `head` function that there is quite a bit of missing data. Let's examine how much missing data is in each column. Produce this output in the cell below"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Let's also look at the count of hourly vs. salaried employees. Write the code in the cell below"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "What this information indicates is that the table contains information about two types of employees - salaried and hourly. Some columns apply only to one type of employee while other columns only apply to another kind. This is why there are so many missing values. Therefore, we will not do anything to handle the missing values."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "There are different departments in the city. List all departments and the count of employees in each department."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Challenge 2 - Hypothesis Tests\n",
- "\n",
- "In this section of the lab, we will test whether the hourly wage of all hourly workers is significantly different from $30/hr. Import the correct one sample test function from scipy and perform the hypothesis test for a 95% two sided confidence interval."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "We are also curious about salaries in the police force. The chief of police in Chicago claimed in a press briefing that salaries this year are higher than last year's mean of $86000/year a year for all salaried employees. Test this one sided hypothesis using a 95% confidence interval.\n",
- "\n",
- "Hint: A one tailed test has a p-value that is half of the two tailed p-value. If our hypothesis is greater than, then to reject, the test statistic must also be positive."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Using the `crosstab` function, find the department that has the most hourly workers. "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "The workers from the department with the most hourly workers have complained that their hourly wage is less than $35/hour. Using a one sample t-test, test this one-sided hypothesis at the 95% confidence level."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Challenge 3: To practice - Constructing Confidence Intervals\n",
- "\n",
- "While testing our hypothesis is a great way to gather empirical evidence for accepting or rejecting the hypothesis, another way to gather evidence is by creating a confidence interval. A confidence interval gives us information about the true mean of the population. So for a 95% confidence interval, we are 95% sure that the mean of the population is within the confidence interval. \n",
- ").\n",
- "\n",
- "To read more about confidence intervals, click [here](https://en.wikipedia.org/wiki/Confidence_interval).\n",
- "\n",
- "\n",
- "In the cell below, we will construct a 95% confidence interval for the mean hourly wage of all hourly workers. \n",
- "\n",
- "The confidence interval is computed in SciPy using the `t.interval` function. You can read more about this function [here](https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.t.html).\n",
- "\n",
- "To compute the confidence interval of the hourly wage, use the 0.95 for the confidence level, number of rows - 1 for degrees of freedom, the mean of the sample for the location parameter and the standard error for the scale. The standard error can be computed using [this](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.sem.html) function in SciPy."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Now construct the 95% confidence interval for all salaried employeed in the police in the cell below."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Bonus Challenge - Hypothesis Tests of Proportions\n",
- "\n",
- "Another type of one sample test is a hypothesis test of proportions. In this test, we examine whether the proportion of a group in our sample is significantly different than a fraction. \n",
- "\n",
- "You can read more about one sample proportion tests [here](http://sphweb.bumc.bu.edu/otlt/MPH-Modules/BS/SAS/SAS6-CategoricalData/SAS6-CategoricalData2.html).\n",
- "\n",
- "In the cell below, use the `proportions_ztest` function from `statsmodels` to perform a hypothesis test that will determine whether the number of hourly workers in the City of Chicago is significantly different from 25% at the 95% confidence level."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Your code here:\n",
- "\n"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.7.3"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
-}
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Before your start:\n",
+ "- Read the README.md file\n",
+ "- Comment as much as you can and use the resources (README.md file)\n",
+ "- Happy learning!"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# import numpy and pandas\n",
+ "\n",
+ "import numpy as np\n",
+ "import pandas as pd"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 1 - Exploring the Data\n",
+ "\n",
+ "In this challenge, we will examine all salaries of employees of the City of Chicago. We will start by loading the dataset and examining its contents."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "db = pd.read_csv(\"Current_Employee_Names__Salaries__and_Position_Titles.csv\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Examine the `salaries` dataset using the `head` function below."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Name | \n",
+ " Job Titles | \n",
+ " Department | \n",
+ " Full or Part-Time | \n",
+ " Salary or Hourly | \n",
+ " Typical Hours | \n",
+ " Annual Salary | \n",
+ " Hourly Rate | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " AARON, JEFFERY M | \n",
+ " SERGEANT | \n",
+ " POLICE | \n",
+ " F | \n",
+ " Salary | \n",
+ " NaN | \n",
+ " 101442.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " AARON, KARINA | \n",
+ " POLICE OFFICER (ASSIGNED AS DETECTIVE) | \n",
+ " POLICE | \n",
+ " F | \n",
+ " Salary | \n",
+ " NaN | \n",
+ " 94122.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " AARON, KIMBERLEI R | \n",
+ " CHIEF CONTRACT EXPEDITER | \n",
+ " GENERAL SERVICES | \n",
+ " F | \n",
+ " Salary | \n",
+ " NaN | \n",
+ " 101592.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " ABAD JR, VICENTE M | \n",
+ " CIVIL ENGINEER IV | \n",
+ " WATER MGMNT | \n",
+ " F | \n",
+ " Salary | \n",
+ " NaN | \n",
+ " 110064.0 | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " ABASCAL, REECE E | \n",
+ " TRAFFIC CONTROL AIDE-HOURLY | \n",
+ " OEMC | \n",
+ " P | \n",
+ " Hourly | \n",
+ " 20.0 | \n",
+ " NaN | \n",
+ " 19.86 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Name Job Titles \\\n",
+ "0 AARON, JEFFERY M SERGEANT \n",
+ "1 AARON, KARINA POLICE OFFICER (ASSIGNED AS DETECTIVE) \n",
+ "2 AARON, KIMBERLEI R CHIEF CONTRACT EXPEDITER \n",
+ "3 ABAD JR, VICENTE M CIVIL ENGINEER IV \n",
+ "4 ABASCAL, REECE E TRAFFIC CONTROL AIDE-HOURLY \n",
+ "\n",
+ " Department Full or Part-Time Salary or Hourly Typical Hours \\\n",
+ "0 POLICE F Salary NaN \n",
+ "1 POLICE F Salary NaN \n",
+ "2 GENERAL SERVICES F Salary NaN \n",
+ "3 WATER MGMNT F Salary NaN \n",
+ "4 OEMC P Hourly 20.0 \n",
+ "\n",
+ " Annual Salary Hourly Rate \n",
+ "0 101442.0 NaN \n",
+ "1 94122.0 NaN \n",
+ "2 101592.0 NaN \n",
+ "3 110064.0 NaN \n",
+ "4 NaN 19.86 "
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "db.head()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We see from looking at the `head` function that there is quite a bit of missing data. Let's examine how much missing data is in each column. Produce this output in the cell below"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Name 0\n",
+ "Job Titles 0\n",
+ "Department 0\n",
+ "Full or Part-Time 0\n",
+ "Salary or Hourly 0\n",
+ "Typical Hours 25161\n",
+ "Annual Salary 8022\n",
+ "Hourly Rate 25161\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "nan_values_db = db.isnull().sum()\n",
+ "\n",
+ "nan_values_db"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's also look at the count of hourly vs. salaried employees. Write the code in the cell below"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "Salary 25161\n",
+ "Hourly 8022\n",
+ "Name: Salary or Hourly, dtype: int64"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "hourly_vs_salaries_employees = db['Salary or Hourly'].value_counts()\n",
+ "\n",
+ "hourly_vs_salaries_employees"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "What this information indicates is that the table contains information about two types of employees - salaried and hourly. Some columns apply only to one type of employee while other columns only apply to another kind. This is why there are so many missing values. Therefore, we will not do anything to handle the missing values."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "There are different departments in the city. List all departments and the count of employees in each department."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Department | \n",
+ " Employee Count | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " ADMIN HEARNG | \n",
+ " 39 | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " ANIMAL CONTRL | \n",
+ " 81 | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " AVIATION | \n",
+ " 1629 | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " BOARD OF ELECTION | \n",
+ " 107 | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " BOARD OF ETHICS | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " BUDGET & MGMT | \n",
+ " 46 | \n",
+ "
\n",
+ " \n",
+ " | 6 | \n",
+ " BUILDINGS | \n",
+ " 269 | \n",
+ "
\n",
+ " \n",
+ " | 7 | \n",
+ " BUSINESS AFFAIRS | \n",
+ " 171 | \n",
+ "
\n",
+ " \n",
+ " | 8 | \n",
+ " CITY CLERK | \n",
+ " 84 | \n",
+ "
\n",
+ " \n",
+ " | 9 | \n",
+ " CITY COUNCIL | \n",
+ " 411 | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " COMMUNITY DEVELOPMENT | \n",
+ " 207 | \n",
+ "
\n",
+ " \n",
+ " | 11 | \n",
+ " COPA | \n",
+ " 116 | \n",
+ "
\n",
+ " \n",
+ " | 12 | \n",
+ " CULTURAL AFFAIRS | \n",
+ " 65 | \n",
+ "
\n",
+ " \n",
+ " | 13 | \n",
+ " DISABILITIES | \n",
+ " 28 | \n",
+ "
\n",
+ " \n",
+ " | 14 | \n",
+ " DoIT | \n",
+ " 99 | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " FAMILY & SUPPORT | \n",
+ " 615 | \n",
+ "
\n",
+ " \n",
+ " | 16 | \n",
+ " FINANCE | \n",
+ " 560 | \n",
+ "
\n",
+ " \n",
+ " | 17 | \n",
+ " FIRE | \n",
+ " 4641 | \n",
+ "
\n",
+ " \n",
+ " | 18 | \n",
+ " GENERAL SERVICES | \n",
+ " 980 | \n",
+ "
\n",
+ " \n",
+ " | 19 | \n",
+ " HEALTH | \n",
+ " 488 | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " HUMAN RELATIONS | \n",
+ " 16 | \n",
+ "
\n",
+ " \n",
+ " | 21 | \n",
+ " HUMAN RESOURCES | \n",
+ " 79 | \n",
+ "
\n",
+ " \n",
+ " | 22 | \n",
+ " INSPECTOR GEN | \n",
+ " 87 | \n",
+ "
\n",
+ " \n",
+ " | 23 | \n",
+ " LAW | \n",
+ " 407 | \n",
+ "
\n",
+ " \n",
+ " | 24 | \n",
+ " LICENSE APPL COMM | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 25 | \n",
+ " MAYOR'S OFFICE | \n",
+ " 85 | \n",
+ "
\n",
+ " \n",
+ " | 26 | \n",
+ " OEMC | \n",
+ " 2102 | \n",
+ "
\n",
+ " \n",
+ " | 27 | \n",
+ " POLICE | \n",
+ " 13414 | \n",
+ "
\n",
+ " \n",
+ " | 28 | \n",
+ " POLICE BOARD | \n",
+ " 2 | \n",
+ "
\n",
+ " \n",
+ " | 29 | \n",
+ " PROCUREMENT | \n",
+ " 92 | \n",
+ "
\n",
+ " \n",
+ " | 30 | \n",
+ " PUBLIC LIBRARY | \n",
+ " 1015 | \n",
+ "
\n",
+ " \n",
+ " | 31 | \n",
+ " STREETS & SAN | \n",
+ " 2198 | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " TRANSPORTN | \n",
+ " 1140 | \n",
+ "
\n",
+ " \n",
+ " | 33 | \n",
+ " TREASURER | \n",
+ " 22 | \n",
+ "
\n",
+ " \n",
+ " | 34 | \n",
+ " WATER MGMNT | \n",
+ " 1879 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Department Employee Count\n",
+ "0 ADMIN HEARNG 39\n",
+ "1 ANIMAL CONTRL 81\n",
+ "2 AVIATION 1629\n",
+ "3 BOARD OF ELECTION 107\n",
+ "4 BOARD OF ETHICS 8\n",
+ "5 BUDGET & MGMT 46\n",
+ "6 BUILDINGS 269\n",
+ "7 BUSINESS AFFAIRS 171\n",
+ "8 CITY CLERK 84\n",
+ "9 CITY COUNCIL 411\n",
+ "10 COMMUNITY DEVELOPMENT 207\n",
+ "11 COPA 116\n",
+ "12 CULTURAL AFFAIRS 65\n",
+ "13 DISABILITIES 28\n",
+ "14 DoIT 99\n",
+ "15 FAMILY & SUPPORT 615\n",
+ "16 FINANCE 560\n",
+ "17 FIRE 4641\n",
+ "18 GENERAL SERVICES 980\n",
+ "19 HEALTH 488\n",
+ "20 HUMAN RELATIONS 16\n",
+ "21 HUMAN RESOURCES 79\n",
+ "22 INSPECTOR GEN 87\n",
+ "23 LAW 407\n",
+ "24 LICENSE APPL COMM 1\n",
+ "25 MAYOR'S OFFICE 85\n",
+ "26 OEMC 2102\n",
+ "27 POLICE 13414\n",
+ "28 POLICE BOARD 2\n",
+ "29 PROCUREMENT 92\n",
+ "30 PUBLIC LIBRARY 1015\n",
+ "31 STREETS & SAN 2198\n",
+ "32 TRANSPORTN 1140\n",
+ "33 TREASURER 22\n",
+ "34 WATER MGMNT 1879"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "department_counts = db.groupby('Department').size().reset_index(name='Employee Count')\n",
+ "\n",
+ "department_counts"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 2 - Hypothesis Tests\n",
+ "\n",
+ "In this section of the lab, we will test whether the hourly wage of all hourly workers is significantly different from $30/hr. Import the correct one sample test function from scipy and perform the hypothesis test for a 95% two sided confidence interval."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "t-statistic: 20.6198057854942\n",
+ "p-value: 4.3230240486229894e-92\n",
+ "Reject the null hypothesis: The hourly wage is significantly different from $30/hr.\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "import scipy.stats as st\n",
+ "from scipy.stats import ttest_1samp\n",
+ "\n",
+ "hourly_wages = db['Hourly Rate'].dropna() # Drop NaN values\n",
+ "\n",
+ "# Perform one-sample t-test\n",
+ "t_statistic, p_value = ttest_1samp(hourly_wages, 30)\n",
+ "\n",
+ "# Checking the results\n",
+ "alpha = 0.05 # 95% confidence level\n",
+ "print(\"t-statistic:\", t_statistic)\n",
+ "print(\"p-value:\", p_value)\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"Reject the null hypothesis: The hourly wage is significantly different from $30/hr.\")\n",
+ "else:\n",
+ " print(\"Fail to reject the null hypothesis: There is not enough evidence to say the hourly wage is significantly different from $30/hr.\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We are also curious about salaries in the police force. The chief of police in Chicago claimed in a press briefing that salaries this year are higher than last year's mean of $86000/year a year for all salaried employees. Test this one sided hypothesis using a 95% confidence interval.\n",
+ "\n",
+ "Hint: A one tailed test has a p-value that is half of the two tailed p-value. If our hypothesis is greater than, then to reject, the test statistic must also be positive."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Reject the null hypothesis: Salaries in the police force are higher than $86,000/year.\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "# Assuming 'Annual Salary' is the column representing annual salaries for salaried employees in the police force\n",
+ "police_salaries = db[db['Department'] == 'POLICE']['Annual Salary'].dropna()\n",
+ "\n",
+ "# Perform one-sided (right-tailed) t-test\n",
+ "t_statistic, p_value = ttest_1samp(police_salaries, 86000)\n",
+ "\n",
+ "# Checking the results\n",
+ "alpha = 0.05 # 95% confidence level\n",
+ "\n",
+ "# Since it's a one-sided test, we compare p-value/2 with alpha\n",
+ "if p_value/2 < alpha and t_statistic > 0:\n",
+ " print(\"Reject the null hypothesis: Salaries in the police force are higher than $86,000/year.\")\n",
+ "else:\n",
+ " print(\"Fail to reject the null hypothesis: There is not enough evidence to say salaries in the police force are higher than $86,000/year.\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Using the `crosstab` function, find the department that has the most hourly workers. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | Salary or Hourly | \n",
+ " Hourly | \n",
+ "
\n",
+ " \n",
+ " | Department | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | STREETS & SAN | \n",
+ " 1862 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ "Salary or Hourly Hourly\n",
+ "Department \n",
+ "STREETS & SAN 1862"
+ ]
+ },
+ "execution_count": 15,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "cross_tab = pd.crosstab(db['Department'], db['Salary or Hourly'])\n",
+ "cross_tab = cross_tab.sort_values(by='Hourly', ascending=False)[['Hourly']][:1]\n",
+ "\n",
+ "cross_tab"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The workers from the department with the most hourly workers have complained that their hourly wage is less than $35/hour. Using a one sample t-test, test this one-sided hypothesis at the 95% confidence level."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "TtestResult(statistic=-9.567447887848152, pvalue=1.6689265282353859e-21, df=1861)"
+ ]
+ },
+ "execution_count": 20,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "street_san_workers = db[(db['Department'] == 'STREETS & SAN') & (db['Salary or Hourly'] == 'Hourly')]\n",
+ "street_san_workers_list = list(street_san_workers['Hourly Rate'])\n",
+ "\n",
+ "st.ttest_1samp(street_san_workers_list,35, alternative='less')\n",
+ "\n",
+ "# The p-value that we got is low, so the salaries are less than 35."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Reject the null hypothesis: Hourly wage is less than $35/hour in the department with the most hourly workers.\n"
+ ]
+ }
+ ],
+ "source": [
+ "hourly_wages_most_hourly_workers = db[db['Department'] == 'POLICE']['Hourly Rate'].dropna()\n",
+ "\n",
+ "# Perform one-sided (left-tailed) t-test\n",
+ "t_statistic, p_value = ttest_1samp(hourly_wages_most_hourly_workers, 35)\n",
+ "\n",
+ "# Checking the results\n",
+ "alpha = 0.05 # 95% confidence level\n",
+ "\n",
+ "# Since it's a one-sided test, we compare p-value/2 with alpha\n",
+ "if p_value/2 < alpha and t_statistic < 0:\n",
+ " print(\"Reject the null hypothesis: Hourly wage is less than $35/hour in the department with the most hourly workers.\")\n",
+ "else:\n",
+ " print(\"Fail to reject the null hypothesis: There is not enough evidence to say the hourly wage is less than $35/hour in the department with the most hourly workers.\")\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Challenge 3: To practice - Constructing Confidence Intervals\n",
+ "\n",
+ "While testing our hypothesis is a great way to gather empirical evidence for accepting or rejecting the hypothesis, another way to gather evidence is by creating a confidence interval. A confidence interval gives us information about the true mean of the population. So for a 95% confidence interval, we are 95% sure that the mean of the population is within the confidence interval. \n",
+ ").\n",
+ "\n",
+ "To read more about confidence intervals, click [here](https://en.wikipedia.org/wiki/Confidence_interval).\n",
+ "\n",
+ "\n",
+ "In the cell below, we will construct a 95% confidence interval for the mean hourly wage of all hourly workers. \n",
+ "\n",
+ "The confidence interval is computed in SciPy using the `t.interval` function. You can read more about this function [here](https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.t.html).\n",
+ "\n",
+ "To compute the confidence interval of the hourly wage, use the 0.95 for the confidence level, number of rows - 1 for degrees of freedom, the mean of the sample for the location parameter and the standard error for the scale. The standard error can be computed using [this](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.sem.html) function in SciPy."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "95% Confidence Interval for Mean Hourly Wage: (32.52345834488425, 33.05365708767623)\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "from scipy.stats import t, sem\n",
+ "\n",
+ "hourly_wages = db['Hourly Rate'].dropna()\n",
+ "\n",
+ "# Compute the mean and standard error of the mean\n",
+ "mean_hourly_wage = np.mean(hourly_wages)\n",
+ "standard_error = sem(hourly_wages)\n",
+ "\n",
+ "# Specify the confidence level and degrees of freedom\n",
+ "confidence_level = 0.95\n",
+ "degrees_of_freedom = len(hourly_wages) - 1\n",
+ "\n",
+ "# Compute the confidence interval\n",
+ "confidence_interval = t.interval(confidence_level, degrees_of_freedom, mean_hourly_wage, standard_error)\n",
+ "\n",
+ "print(f\"95% Confidence Interval for Mean Hourly Wage: {confidence_interval}\")\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now construct the 95% confidence interval for all salaried employeed in the police in the cell below."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "95% Confidence Interval for Mean Annual Salary in the Police Department: (86177.05631531784, 86795.77269094894)\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "\n",
+ "salaries_police = db[(db['Department'] == 'POLICE') & (db['Salary or Hourly'] == 'Salary')]['Annual Salary'].dropna()\n",
+ "\n",
+ "mean_salary_police = np.mean(salaries_police)\n",
+ "standard_error_police = sem(salaries_police)\n",
+ "\n",
+ "confidence_level = 0.95\n",
+ "degrees_of_freedom = len(salaries_police) - 1\n",
+ "\n",
+ "confidence_interval_police = t.interval(confidence_level, degrees_of_freedom, mean_salary_police, standard_error_police)\n",
+ "\n",
+ "print(f\"95% Confidence Interval for Mean Annual Salary in the Police Department: {confidence_interval_police}\")\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Bonus Challenge - Hypothesis Tests of Proportions\n",
+ "\n",
+ "Another type of one sample test is a hypothesis test of proportions. In this test, we examine whether the proportion of a group in our sample is significantly different than a fraction. \n",
+ "\n",
+ "You can read more about one sample proportion tests [here](http://sphweb.bumc.bu.edu/otlt/MPH-Modules/BS/SAS/SAS6-CategoricalData/SAS6-CategoricalData2.html).\n",
+ "\n",
+ "In the cell below, use the `proportions_ztest` function from `statsmodels` to perform a hypothesis test that will determine whether the number of hourly workers in the City of Chicago is significantly different from 25% at the 95% confidence level."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Reject the null hypothesis: The proportion of hourly workers is significantly different from 25%.\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Your code here:\n",
+ "from statsmodels.stats.proportion import proportions_ztest\n",
+ "\n",
+ "hourly_workers = db[db['Salary or Hourly'] == 'Hourly']\n",
+ "\n",
+ "# Number of successes (hourly workers) and total observations\n",
+ "successes = len(hourly_workers)\n",
+ "total_observations = len(db)\n",
+ "\n",
+ "# The proportion to test against (25%)\n",
+ "proportion_to_test = 0.25\n",
+ "\n",
+ "# Perform proportions z-test\n",
+ "z_stat, p_value = proportions_ztest(successes, total_observations, proportion_to_test)\n",
+ "\n",
+ "# Checking the results\n",
+ "alpha = 0.05 # 95% confidence level\n",
+ "\n",
+ "if p_value < alpha:\n",
+ " print(\"Reject the null hypothesis: The proportion of hourly workers is significantly different from 25%.\")\n",
+ "else:\n",
+ " print(\"Fail to reject the null hypothesis: There is not enough evidence to say the proportion of hourly workers is significantly different from 25%.\")\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.10.9"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}