From 39d587b09d218bbb5edb920521ed3af282ffa093 Mon Sep 17 00:00:00 2001 From: Silvia Gonzalez <80603632+silviagonzalez98@users.noreply.github.com> Date: Wed, 6 Oct 2021 20:10:35 +0200 Subject: [PATCH 1/3] Add files via upload --- Solutions (6).ipynb | 623 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 623 insertions(+) create mode 100644 Solutions (6).ipynb diff --git a/Solutions (6).ipynb b/Solutions (6).ipynb new file mode 100644 index 0000000..d8a4de7 --- /dev/null +++ b/Solutions (6).ipynb @@ -0,0 +1,623 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "95c7ba62", + "metadata": {}, + "source": [ + "# Lab | Inferential statistics - ANOVA\n", + "\n", + "Note: The following lab is divided in 2 sections which represent activities 3 and 4.\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "c4f63c48", + "metadata": {}, + "source": [ + "\n", + "## Part 1\n", + "\n", + "In this activity, we will look at another example. Your task is to understand the problem and write down all the steps to set up ANOVA. After the next lesson, we will ask you to solve this problem using Python. Here are the steps that you would need to work on:\n", + " - Null hypothesis\n", + " - Alternate hypothesis\n", + " - Level of significance\n", + " - Test statistic\n", + " - P-value\n", + " - F table\n", + "\n", + "### Context\n", + "\n", + "Suppose you are working as an analyst in a microprocessor chip manufacturing plant. You have been given the task of analyzing a plasma etching process with respect to changing Power (in Watts) of the plasma beam. Data was collected and provided to you to conduct statistical analysis and check if changing the power of the plasma beam has any effect on the etching rate by the machine. You will conduct ANOVA and check if there is any difference in the mean etching rate for different levels of power. You can find the data `anova_lab_data.xlsx` file in the `files_for_lab` folder \n", + "\n", + "Data was collected randomly and provided to you in the table as shown: [link to the image - Data](https://education-team-2020.s3-eu-west-1.amazonaws.com/data-analytics/7.05/7.05-lab_data.png)\n", + "\n", + "- State the null hypothesis\n", + "\n", + "H0 = The power of plasma bean DOES NOT have a significant effect on etching rate by the machine. \n", + "\n", + "- State the alternate hypothesis\n", + "\n", + "H1 = The power of plasma bean has a significant effect on etching rate by the machine. \n", + "\n", + "- What is the significance level\n", + "\n", + "Significance level = 0.05\n", + "\n", + "- What are the degrees of freedom of model, error terms, and total DoF\n", + "\n", + "Degrees of freedom = 5 - 1 = 4\n", + "\n", + "Error terms = (?)\n", + "\n", + "Total DoF = (?)\n" + ] + }, + { + "cell_type": "markdown", + "id": "caf389fc", + "metadata": {}, + "source": [ + "## Part 2\n", + "\n", + "- In this section, use Python to conduct ANOVA.\n", + "- What conclusions can you draw from the experiment and why?" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "f182b9b4", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "import warnings\n", + "warnings.filterwarnings('ignore')" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "8f0a4c44", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PowerEtching Rate
0160 W5.43
1180 W6.24
2200 W8.79
3160 W5.71
4180 W6.71
5200 W9.20
6160 W6.22
7180 W5.98
8200 W7.90
9160 W6.01
10180 W5.66
11200 W8.15
12160 W5.59
13180 W6.60
14200 W7.55
\n", + "
" + ], + "text/plain": [ + " Power Etching Rate\n", + "0 160 W 5.43\n", + "1 180 W 6.24\n", + "2 200 W 8.79\n", + "3 160 W 5.71\n", + "4 180 W 6.71\n", + "5 200 W 9.20\n", + "6 160 W 6.22\n", + "7 180 W 5.98\n", + "8 200 W 7.90\n", + "9 160 W 6.01\n", + "10 180 W 5.66\n", + "11 200 W 8.15\n", + "12 160 W 5.59\n", + "13 180 W 6.60\n", + "14 200 W 7.55" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data = pd.read_excel('files_for_lab/anova_lab_data.xlsx')\n", + "data" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "3e4efb11", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Etching Rate
count15.000000
mean6.782667
std1.228643
min5.430000
25%5.845000
50%6.240000
75%7.725000
max9.200000
\n", + "
" + ], + "text/plain": [ + " Etching Rate\n", + "count 15.000000\n", + "mean 6.782667\n", + "std 1.228643\n", + "min 5.430000\n", + "25% 5.845000\n", + "50% 6.240000\n", + "75% 7.725000\n", + "max 9.200000" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.describe()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3b364f93", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Etching Rate
Power
160 W5.792
180 W6.238
200 W8.318
\n", + "
" + ], + "text/plain": [ + " Etching Rate\n", + "Power \n", + "160 W 5.792\n", + "180 W 6.238\n", + "200 W 8.318" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.groupby('Power ').agg(np.mean)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "ea80d7a2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
poweretching_rate
0160 W5.43
1180 W6.24
2200 W8.79
3160 W5.71
4180 W6.71
5200 W9.20
6160 W6.22
7180 W5.98
8200 W7.90
9160 W6.01
10180 W5.66
11200 W8.15
12160 W5.59
13180 W6.60
14200 W7.55
\n", + "
" + ], + "text/plain": [ + " power etching_rate\n", + "0 160 W 5.43\n", + "1 180 W 6.24\n", + "2 200 W 8.79\n", + "3 160 W 5.71\n", + "4 180 W 6.71\n", + "5 200 W 9.20\n", + "6 160 W 6.22\n", + "7 180 W 5.98\n", + "8 200 W 7.90\n", + "9 160 W 6.01\n", + "10 180 W 5.66\n", + "11 200 W 8.15\n", + "12 160 W 5.59\n", + "13 180 W 6.60\n", + "14 200 W 7.55" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Standardize column headers\n", + "\n", + "data.rename(columns={'Power ': 'power', 'Etching Rate': 'etching_rate'}, inplace=True)\n", + "data" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "a7d1bb7c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
dfsum_sqmean_sqFPR(>F)
C(power)2.018.1766539.08832736.8789550.000008
Residual12.02.9572400.246437NaNNaN
\n", + "
" + ], + "text/plain": [ + " df sum_sq mean_sq F PR(>F)\n", + "C(power) 2.0 18.176653 9.088327 36.878955 0.000008\n", + "Residual 12.0 2.957240 0.246437 NaN NaN" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import statsmodels.api as sm\n", + "from statsmodels.formula.api import ols\n", + "\n", + "model = ols('etching_rate ~ C(power)',data=data).fit()\n", + "sm.stats.anova_lm(model)" + ] + }, + { + "cell_type": "markdown", + "id": "a370d0ca", + "metadata": {}, + "source": [ + "Conclusion: Considering a significance level of 0.05, the p-value is below (=0.000008), so we reject the null hypothesis. Therefore, at least one change of the plasma beam power has significant effect on the etching rate by the machine." + ] + } + ], + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 04a75eb24f3f46a9e7b21cddde95b9b18b52497e Mon Sep 17 00:00:00 2001 From: Silvia Gonzalez <80603632+silviagonzalez98@users.noreply.github.com> Date: Wed, 6 Oct 2021 20:10:49 +0200 Subject: [PATCH 2/3] Delete Untitled.ipynb --- Untitled.ipynb | 100 ------------------------------------------------- 1 file changed, 100 deletions(-) delete mode 100644 Untitled.ipynb diff --git a/Untitled.ipynb b/Untitled.ipynb deleted file mode 100644 index 7b5f0b3..0000000 --- a/Untitled.ipynb +++ /dev/null @@ -1,100 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "95c7ba62", - "metadata": {}, - "source": [ - "# Lab | Inferential statistics - ANOVA\n", - "\n", - "Note: The following lab is divided in 2 sections which represent activities 3 and 4.\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "id": "c4f63c48", - "metadata": {}, - "source": [ - "\n", - "## Part 1\n", - "\n", - "In this activity, we will look at another example. Your task is to understand the problem and write down all the steps to set up ANOVA. After the next lesson, we will ask you to solve this problem using Python. Here are the steps that you would need to work on:\n", - " - Null hypothesis\n", - " - Alternate hypothesis\n", - " - Level of significance\n", - " - Test statistic\n", - " - P-value\n", - " - F table\n", - "\n", - "### Context\n", - "\n", - "Suppose you are working as an analyst in a microprocessor chip manufacturing plant. You have been given the task of analyzing a plasma etching process with respect to changing Power (in Watts) of the plasma beam. Data was collected and provided to you to conduct statistical analysis and check if changing the power of the plasma beam has any effect on the etching rate by the machine. You will conduct ANOVA and check if there is any difference in the mean etching rate for different levels of power. You can find the data `anova_lab_data.xlsx` file in the `files_for_lab` folder \n", - "\n", - "- State the null hypothesis\n", - "- State the alternate hypothesis\n", - "- What is the significance level\n", - "- What are the degrees of freedom of model, error terms, and total DoF\n", - "\n", - "Data was collected randomly and provided to you in the table as shown: [link to the image - Data](https://education-team-2020.s3-eu-west-1.amazonaws.com/data-analytics/7.05/7.05-lab_data.png)\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f56d81a7", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a891a030", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "caf389fc", - "metadata": {}, - "source": [ - "## Part 2\n", - "\n", - "- In this section, use Python to conduct ANOVA.\n", - "- What conclusions can you draw from the experiment and why?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f182b9b4", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "ironhack", - "language": "python", - "name": "ironhack" - }, - "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.8.5" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} From 740582350bb413e4386ecf5187b15873dabb5187 Mon Sep 17 00:00:00 2001 From: Silvia Gonzalez <80603632+silviagonzalez98@users.noreply.github.com> Date: Wed, 6 Oct 2021 20:11:01 +0200 Subject: [PATCH 3/3] Rename Solutions (6).ipynb to Solutions.ipynb --- Solutions (6).ipynb => Solutions.ipynb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Solutions (6).ipynb => Solutions.ipynb (100%) diff --git a/Solutions (6).ipynb b/Solutions.ipynb similarity index 100% rename from Solutions (6).ipynb rename to Solutions.ipynb