diff --git a/module2/exo5/exo5_R_en.org b/module2/exo5/exo5_R_en.org new file mode 100644 index 0000000000000000000000000000000000000000..e299e975cef035d5d8f0cd1f72731d7b8fd1cf83 --- /dev/null +++ b/module2/exo5/exo5_R_en.org @@ -0,0 +1,201 @@ +#+TITLE: Analysis of the risk of failure of the O-rings on the Challenger shuttle +#+AUTHOR: Arnaud Legrand +#+LANGUAGE: en + +#+HTML_HEAD: +#+HTML_HEAD: +#+HTML_HEAD: +#+HTML_HEAD: +#+HTML_HEAD: +#+HTML_HEAD: + +#+LATEX_HEADER: \usepackage[utf8]{inputenc} +#+LATEX_HEADER: \usepackage[T1]{fontenc} +#+LATEX_HEADER: \usepackage[a4paper,margin=.8in]{geometry} +#+LATEX_HEADER: \usepackage[french]{babel} + +# #+PROPERTY: header-args :session :exports both + +On January 27, 1986, the day before the takeoff of the shuttle /Challenger/, had +a three-hour teleconference was held between +Morton Thiokol (the manufacturer of one of the engines) and NASA. The +discussion focused on the consequences of the +temperature at take-off of 31°F (just below +0°C) for the success of the flight and in particular on the performance of the +O-rings used in the engines. Indeed, no test +had been performed at this temperature. + +The following study takes up some of the analyses carried out that +night with the objective of assessing the potential influence of +the temperature and pressure to which the O-rings are subjected +on their probability of malfunction. Our starting point is +the results of the experiments carried out by NASA engineers +during the six years preceding the launch of the shuttle +Challenger. + +* Loading the data +We start by loading this data: +#+begin_src R :results output :session *R* :exports both +data = read.csv("shuttle.csv",header=T) +data +#+end_src + +#+RESULTS: +#+begin_example + Date Count Temperature Pressure Malfunction +1 4/12/81 6 66 50 0 +2 11/12/81 6 70 50 1 +3 3/22/82 6 69 50 0 +4 11/11/82 6 68 50 0 +5 4/04/83 6 67 50 0 +6 6/18/82 6 72 50 0 +7 8/30/83 6 73 100 0 +8 11/28/83 6 70 100 0 +9 2/03/84 6 57 200 1 +10 4/06/84 6 63 200 1 +11 8/30/84 6 70 200 1 +12 10/05/84 6 78 200 0 +13 11/08/84 6 67 200 0 +14 1/24/85 6 53 200 2 +15 4/12/85 6 67 200 0 +16 4/29/85 6 75 200 0 +17 6/17/85 6 70 200 0 +18 7/2903/85 6 81 200 0 +19 8/27/85 6 76 200 0 +20 10/03/85 6 79 200 0 +21 10/30/85 6 75 200 2 +22 11/26/85 6 76 200 0 +23 1/12/86 6 58 200 1 +#+end_example + +The data set shows us the date of each test, the number of O-rings +(there are 6 on the main launcher), the +temperature (in Fahrenheit) and pressure (in psi), and finally the +number of identified malfunctions. + +* Graphical inspection +Flights without incidents do not provide any information +on the influence of temperature or pressure on malfunction. +We thus focus on the experiments in which at least one O-ring was defective. + +#+begin_src R :results output :session *R* :exports both +data = data[data$Malfunction>0,] +data +#+end_src + +#+RESULTS: +: Date Count Temperature Pressure Malfunction +: 2 11/12/81 6 70 50 1 +: 9 2/03/84 6 57 200 1 +: 10 4/06/84 6 63 200 1 +: 11 8/30/84 6 70 200 1 +: 14 1/24/85 6 53 200 2 +: 21 10/30/85 6 75 200 2 +: 23 1/12/86 6 58 200 1 + +We have a high temperature variability but +the pressure is almost always 200, which should +simplify the analysis. + +How does the frequency of failure vary with temperature? +#+begin_src R :results output graphics :file "freq_temp.png" :exports both :width 600 :height 400 :session *R* +plot(data=data, Malfunction/Count ~ Temperature, ylim=c(0,1)) +#+end_src + +#+RESULTS: +[[file:freq_temp.png]] + +At first glance, the dependence does not look very important, but let's try to +estimate the impact of temperature $t$ on the probability of O-ring malfunction. + +* Estimation of the temperature influence + +Suppose that each of the six O-rings is damaged with the same +probability and independently of the others and that this probability +depends only on the temperature. If $p(t)$ is this probability, the +number $D$ of malfunctioning O-rings during a flight at +temperature $t$ follows a binomial law with parameters $n=6$ and +$p=p(t)$. To link $p(t)$ to $t$, we will therefore perform a +logistic regression. + +#+begin_src R :results output :session *R* :exports both +logistic_reg = glm(data=data, Malfunction/Count ~ Temperature, weights=Count, + family=binomial(link='logit')) +summary(logistic_reg) +#+end_src + +#+RESULTS: +#+begin_example + +Call: +glm(formula = Malfunction/Count ~ Temperature, family = binomial(link = "logit"), + data = data, weights = Count) + +Deviance Residuals: + 2 9 10 11 14 21 23 +-0.3015 -0.2836 -0.2919 -0.3015 0.6891 0.6560 -0.2850 + +Coefficients: + Estimate Std. Error z value Pr(>|z|) +(Intercept) -1.389528 3.195752 -0.435 0.664 +Temperature 0.001416 0.049773 0.028 0.977 + +(Dispersion parameter for binomial family taken to be 1) + + Null deviance: 1.3347 on 6 degrees of freedom +Residual deviance: 1.3339 on 5 degrees of freedom +AIC: 18.894 + +Number of Fisher Scoring iterations: 4 +#+end_example + +The most likely estimator of the temperature parameter is 0.001416 +and the standard error of this estimator is 0.049, in other words we +cannot distinguish any particular impact and we must take our +estimates with caution. + +* Estimation of the probability of O-ring malfunction +The expected temperature on the take-off day is 31°F. Let's try to +estimate the probability of O-ring malfunction at +this temperature from the model we just built: + +#+begin_src R :results output graphics :file "proba_estimate.png" :exports both :width 600 :height 400 :session *R* +# shuttle=shuttle[shuttle$r!=0,] +tempv = seq(from=30, to=90, by = .5) +rmv <- predict(logistic_reg,list(Temperature=tempv),type="response") +plot(tempv,rmv,type="l",ylim=c(0,1)) +points(data=data, Malfunction/Count ~ Temperature) +#+end_src + +#+RESULTS: +[[file:proba_estimate.png]] + +As expected from the initial data, the +temperature has no significant impact on the probability of failure of the +O-rings. It will be about 0.2, as in the tests +where we had a failure of at least one joint. Let's get back to the initial dataset to estimate the probability of failure: + +#+begin_src R :results output :session *R* :exports both +data_full = read.csv("shuttle.csv",header=T) +sum(data_full$Malfunction)/sum(data_full$Count) +#+end_src + +#+RESULTS: +: [1] 0.06521739 + +This probability is thus about $p=0.065$. Knowing that there is +a primary and a secondary O-ring on each of the three parts of the +launcher, the probability of failure of both joints of a launcher +is $p^2 \approx 0.00425$. The probability of failure of any one of the +launchers is $1-(1-p^2)^3 \approx 1.2%$. That would really be +bad luck.... Everything is under control, so the takeoff can happen +tomorrow as planned. + +But the next day, the Challenger shuttle exploded and took away +with her the seven crew members. The public was shocked and in +the subsequent investigation, the reliability of the +O-rings was questioned. Beyond the internal communication problems +of NASA, which have a lot to do with this fiasco, the previous analysis +includes (at least) a small problem.... Can you find it? +You are free to modify this analysis and to look at this dataset +from all angles in order to to explain what's wrong. diff --git a/module2/exo5/exo5_R.org b/module2/exo5/exo5_R_fr.org similarity index 100% rename from module2/exo5/exo5_R.org rename to module2/exo5/exo5_R_fr.org diff --git a/module2/exo5/exo5_en.Rmd b/module2/exo5/exo5_en.Rmd new file mode 100644 index 0000000000000000000000000000000000000000..f9003e3a9de8b87c66b620b3fb5157fc127a4e17 --- /dev/null +++ b/module2/exo5/exo5_en.Rmd @@ -0,0 +1,119 @@ +--- +title: "Analysis of the risk of failure of the O-rings on the Challenger shuttle" +author: "Arnaud Legrand" +date: "28 juin 2018" +output: html_document +--- + +On January 27, 1986, the day before the takeoff of the shuttle _Challenger_, had +a three-hour teleconference was held between +Morton Thiokol (the manufacturer of one of the engines) and NASA. The +discussion focused on the consequences of the +temperature at take-off of 31°F (just below +0°C) for the success of the flight and in particular on the performance of the +O-rings used in the engines. Indeed, no test +had been performed at this temperature. + +The following study takes up some of the analyses carried out that +night with the objective of assessing the potential influence of +the temperature and pressure to which the O-rings are subjected +on their probability of malfunction. Our starting point is +the results of the experiments carried out by NASA engineers +during the six years preceding the launch of the shuttle +Challenger. + +# Loading the data +We start by loading this data: + +```{r} +data = read.csv("shuttle.csv",header=T) +data +``` + +The data set shows us the date of each test, the number of O-rings +(there are 6 on the main launcher), the +temperature (in Fahrenheit) and pressure (in psi), and finally the +number of identified malfunctions. + +# Graphical inspection +Flights without incidents do not provide any information +on the influence of temperature or pressure on malfunction. +We thus focus on the experiments in which at least one O-ring was defective. + +```{r} +data = data[data$Malfunction>0,] +data +``` + +We have a high temperature variability but +the pressure is almost always 200, which should +simplify the analysis. + +How does the frequency of failure vary with temperature? +```{r} +plot(data=data, Malfunction/Count ~ Temperature, ylim=c(0,1)) +``` + +At first glance, the dependence does not look very important, but let's try to +estimate the impact of temperature $t$ on the probability of O-ring malfunction. + +# Estimation of the temperature influence + +Suppose that each of the six O-rings is damaged with the same +probability and independently of the others and that this probability +depends only on the temperature. If $p(t)$ is this probability, the +number $D$ of malfunctioning O-rings during a flight at +temperature $t$ follows a binomial law with parameters $n=6$ and +$p=p(t)$. To link $p(t)$ to $t$, we will therefore perform a +logistic regression. + +```{r} +logistic_reg = glm(data=data, Malfunction/Count ~ Temperature, weights=Count, + family=binomial(link='logit')) +summary(logistic_reg) +``` + +The most likely estimator of the temperature parameter is 0.001416 +and the standard error of this estimator is 0.049, in other words we +cannot distinguish any particular impact and we must take our +estimates with caution. + +# Estimation of the probability of O-ring malfunction +The expected temperature on the take-off day is 31°F. Let's try to +estimate the probability of O-ring malfunction at +this temperature from the model we just built: + +```{r} +# shuttle=shuttle[shuttle$r!=0,] +tempv = seq(from=30, to=90, by = .5) +rmv <- predict(logistic_reg,list(Temperature=tempv),type="response") +plot(tempv,rmv,type="l",ylim=c(0,1)) +points(data=data, Malfunction/Count ~ Temperature) +``` + +As expected from the initial data, the +temperature has no significant impact on the probability of failure of the +O-rings. It will be about 0.2, as in the tests +where we had a failure of at least one joint. Let's get back to the initial dataset to estimate the probability of failure: + +```{r} +data_full = read.csv("shuttle.csv",header=T) +sum(data_full$Malfunction)/sum(data_full$Count) +``` + +This probability is thus about $p=0.065$. Knowing that there is +a primary and a secondary O-ring on each of the three parts of the +launcher, the probability of failure of both joints of a launcher +is $p^2 \approx 0.00425$. The probability of failure of any one of the +launchers is $1-(1-p^2)^3 \approx 1.2%$. That would really be +bad luck.... Everything is under control, so the takeoff can happen +tomorrow as planned. + +But the next day, the Challenger shuttle exploded and took away +with her the seven crew members. The public was shocked and in +the subsequent investigation, the reliability of the +O-rings was questioned. Beyond the internal communication problems +of NASA, which have a lot to do with this fiasco, the previous analysis +includes (at least) a small problem.... Can you find it? +You are free to modify this analysis and to look at this dataset +from all angles in order to to explain what's wrong. diff --git a/module2/exo5/exo5_en.ipynb b/module2/exo5/exo5_en.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..d3fb0b6ffc4bdef5ab4134ae39a1c60c45e34204 --- /dev/null +++ b/module2/exo5/exo5_en.ipynb @@ -0,0 +1,720 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Analysis of the risk of failure of the O-rings on the Challenger shuttle" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "On January 27, 1986, the day before the takeoff of the shuttle _Challenger_, had\n", + "a three-hour teleconference was held between \n", + "Morton Thiokol (the manufacturer of one of the engines) and NASA. The\n", + "discussion focused on the consequences of the\n", + "temperature at take-off of 31°F (just below\n", + "0°C) for the success of the flight and in particular on the performance of the\n", + "O-rings used in the engines. Indeed, no test\n", + "had been performed at this temperature.\n", + "\n", + "The following study takes up some of the analyses carried out that\n", + "night with the objective of assessing the potential influence of\n", + "the temperature and pressure to which the O-rings are subjected\n", + "on their probability of malfunction. Our starting point is \n", + "the results of the experiments carried out by NASA engineers\n", + "during the six years preceding the launch of the shuttle\n", + "Challenger." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Loading the data\n", + "We start by loading this data:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "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", + " \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", + " \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", + "
DateCountTemperaturePressureMalfunction
04/12/81666500
111/12/81670501
23/22/82669500
311/11/82668500
44/04/83667500
56/18/82672500
68/30/836731000
711/28/836701000
82/03/846572001
94/06/846632001
108/30/846702001
1110/05/846782000
1211/08/846672000
131/24/856532002
144/12/856672000
154/29/856752000
166/17/856702000
177/2903/856812000
188/27/856762000
1910/03/856792000
2010/30/856752002
2111/26/856762000
221/12/866582001
\n", + "
" + ], + "text/plain": [ + " Date Count Temperature Pressure Malfunction\n", + "0 4/12/81 6 66 50 0\n", + "1 11/12/81 6 70 50 1\n", + "2 3/22/82 6 69 50 0\n", + "3 11/11/82 6 68 50 0\n", + "4 4/04/83 6 67 50 0\n", + "5 6/18/82 6 72 50 0\n", + "6 8/30/83 6 73 100 0\n", + "7 11/28/83 6 70 100 0\n", + "8 2/03/84 6 57 200 1\n", + "9 4/06/84 6 63 200 1\n", + "10 8/30/84 6 70 200 1\n", + "11 10/05/84 6 78 200 0\n", + "12 11/08/84 6 67 200 0\n", + "13 1/24/85 6 53 200 2\n", + "14 4/12/85 6 67 200 0\n", + "15 4/29/85 6 75 200 0\n", + "16 6/17/85 6 70 200 0\n", + "17 7/2903/85 6 81 200 0\n", + "18 8/27/85 6 76 200 0\n", + "19 10/03/85 6 79 200 0\n", + "20 10/30/85 6 75 200 2\n", + "21 11/26/85 6 76 200 0\n", + "22 1/12/86 6 58 200 1" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "import pandas as pd\n", + "data = pd.read_csv(\"shuttle.csv\")\n", + "data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The data set shows us the date of each test, the number of O-rings (there are 6 on the main launcher), the temperature (in Fahrenheit) and pressure (in psi), and finally the number of identified malfunctions." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Graphical inspection\n", + "Flights without incidents do not provide any information\n", + "on the influence of temperature or pressure on malfunction.\n", + "We thus focus on the experiments in which at least one O-ring\n", + "was defective." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "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", + "
DateCountTemperaturePressureMalfunction
111/12/81670501
82/03/846572001
94/06/846632001
108/30/846702001
131/24/856532002
2010/30/856752002
221/12/866582001
\n", + "
" + ], + "text/plain": [ + " Date Count Temperature Pressure Malfunction\n", + "1 11/12/81 6 70 50 1\n", + "8 2/03/84 6 57 200 1\n", + "9 4/06/84 6 63 200 1\n", + "10 8/30/84 6 70 200 1\n", + "13 1/24/85 6 53 200 2\n", + "20 10/30/85 6 75 200 2\n", + "22 1/12/86 6 58 200 1" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data = data[data.Malfunction>0]\n", + "data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We have a high temperature variability but\n", + "the pressure is almost always 200, which should\n", + "simplify the analysis.\n", + "\n", + "How does the frequency of failure vary with temperature?" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFWxJREFUeJzt3X20ZXV93/H3Zx6AQaZAoJ0kMxAxUCwNSHAEDSYdS2JB\nV8AsEgVrsaRmwhLSZdomUJc1xCRrVRKt2og4UhTsakgUH0g7lkDSq4kRAc1kBrDgFBFmMKAjCheH\neeB++8fZs3Pm3jt3zoW7z2Hufb/WumvOfjj7fO939pzP7IfzO6kqJEkCWDTqAiRJzx+GgiSpZShI\nklqGgiSpZShIklqGgiSp1VkoJLkuyWNJ7t7H8iT5QJLNSTYmOa2rWiRJg+nySOFjwNkzLD8HOKH5\nWQt8qMNaJEkD6CwUquoLwHdnWOU84IbquR04IsmPdFWPJGn/lozwtVcCD/dNb2nmfWvyiknW0jua\nYNmyZS895phjhlLgczUxMcGiRV626WdPprIn07MvUz2Xntx///3fqap/uL/1RhkKA6uqdcA6gNWr\nV9ddd9014ooGMz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w/qp6GXBys+zsqvpjYAPwhqo6dYDTWy8GzqqqNwFrgceq6nTgZfQGYDz22fRH6uc1BS0E\nP0vvjfOuJADLgIebZdur6tbm8Sbg+1W1O8km4IV927ilqh4HSPIZ4JX0/v3sa7s7+fthTwDOSvIb\nwCHA0cBXgM/N8vf4bFU93Tx+NfBPkvSH0An0hkWQnjVDQQtBgOuq6j/tNTNZQu/Ne48JYEff4/5/\nH5MvvtV+tru9Ge6ZJIcCf0hvNNStSX6XXjhMZzd/fwQ/eZ2nJv1Ob62qP0eaQ54+0kJwG/D6JEdD\n7y6lZ3Gq5dXpfbfyofS+EeyLs9juMnoh851mJN3z+5Y9CSzvm34QeGnzuH+9yW4B3toE0J7v9F02\ny99JmsIjBc17VbUpyW/T+1a8RcAu4BLgkVls5k56Qzf/KHD9nruFBtluVW1L73uZ76X3xShf7lv8\nUeDaJNvpXbe4EvhIku8BX5ihng/TGz10Q3Pq6jF6YSU9J96SKu1Hc2fPT1TV20Zdi9Q1Tx9Jkloe\nKUiSWh4pSJJahoIkqWUoSJJahoIkqWUoSJJa/x9HrV1ZOc+mWgAAAABJRU5ErkJggg==\n", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%matplotlib inline\n", + "pd.set_option('mode.chained_assignment',None) # this removes a useless warning from pandas\n", + "import matplotlib.pyplot as plt\n", + "\n", + "data[\"Frequency\"]=data.Malfunction/data.Count\n", + "data.plot(x=\"Temperature\",y=\"Frequency\",kind=\"scatter\",ylim=[0,1])\n", + "plt.grid(True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "At first glance, the dependence does not look very important, but let's try to\n", + "estimate the impact of temperature $t$ on the probability of O-ring malfunction." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Estimation of the temperature influence\n", + "\n", + "Suppose that each of the six O-rings is damaged with the same\n", + "probability and independently of the others and that this probability\n", + "depends only on the temperature. If $p(t)$ is this probability, the\n", + "number $D$ of malfunctioning O-rings during a flight at\n", + "temperature $t$ follows a binomial law with parameters $n=6$ and\n", + "$p=p(t)$. To link $p(t)$ to $t$, we will therefore perform a\n", + "logistic regression." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/hinsen/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/compat/pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.\n", + " from pandas.core import datetools\n" + ] + }, + { + "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", + "
Generalized Linear Model Regression Results
Dep. Variable: Frequency No. Observations: 7
Model: GLM Df Residuals: 5
Model Family: Binomial Df Model: 1
Link Function: logit Scale: 1.0
Method: IRLS Log-Likelihood: -3.6370
Date: Wed, 27 Mar 2019 Deviance: 3.3763
Time: 13:03:27 Pearson chi2: 0.236
No. Iterations: 5
\n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "\n", + " \n", + "\n", + "
coef std err z P>|z| [0.025 0.975]
Intercept -1.3895 7.828 -0.178 0.859 -16.732 13.953
Temperature 0.0014 0.122 0.012 0.991 -0.238 0.240
" + ], + "text/plain": [ + "\n", + "\"\"\"\n", + " Generalized Linear Model Regression Results \n", + "==============================================================================\n", + "Dep. Variable: Frequency No. Observations: 7\n", + "Model: GLM Df Residuals: 5\n", + "Model Family: Binomial Df Model: 1\n", + "Link Function: logit Scale: 1.0\n", + "Method: IRLS Log-Likelihood: -3.6370\n", + "Date: Wed, 27 Mar 2019 Deviance: 3.3763\n", + "Time: 13:03:27 Pearson chi2: 0.236\n", + "No. Iterations: 5 \n", + "===============================================================================\n", + " coef std err z P>|z| [0.025 0.975]\n", + "-------------------------------------------------------------------------------\n", + "Intercept -1.3895 7.828 -0.178 0.859 -16.732 13.953\n", + "Temperature 0.0014 0.122 0.012 0.991 -0.238 0.240\n", + "===============================================================================\n", + "\"\"\"" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import statsmodels.api as sm\n", + "\n", + "data[\"Success\"]=data.Count-data.Malfunction\n", + "data[\"Intercept\"]=1\n", + "\n", + "logmodel=sm.GLM(data['Frequency'], data[['Intercept','Temperature']], family=sm.families.Binomial(sm.families.links.logit)).fit()\n", + "\n", + "logmodel.summary()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The most likely estimator of the temperature parameter is 0.0014\n", + "and the standard error of this estimator is 0.122, in other words we\n", + "cannot distinguish any particular impact and we must take our\n", + "estimates with caution." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Estimation of the probability of O-ring malfunction\n", + "\n", + "The expected temperature on the take-off day is 31°F. Let's try to\n", + "estimate the probability of O-ring malfunction at\n", + "this temperature from the model we just built:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEKCAYAAADpfBXhAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGwxJREFUeJzt3X901fWd5/HnOwlIIAiCygChC7NLcW2VXyGosG7Q4Vfb\nQd11RHSc1h2WulPa6e6RrZzTWe2MnrNzcOfQ6Vopqwzt8Wh0HEXtMoXqmDrjaA0IgsDwYy3VRFuE\nFiEalCTv/eP7vcn3XhJyc7nJvffj63FODvf7/X6+n+/nnct95ZvP/d5vzN0REZGwlBV6ACIikn8K\ndxGRACncRUQCpHAXEQmQwl1EJEAKdxGRAPUa7ma2wcyOmNmbPWw3M/trMztkZrvMbEb+hykiIn2R\nzZn7RmDRWbYvBibHXyuAB899WCIici56DXd3fwn4zVmaXAf8y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L9Dro\nqd9P6LrVAsC1ZrYKGAJcCGwH/r6PdTzj7qfixwuAf2tmyR8mk4luISCSM4W7lBIDNrj7n6WtNKsg\nCuGUDqK/4JV6nPx/nvkmk/fSb2t8S1bi+3H/b2CGuzeb2b1EId+dNrp+M85s82FGTX/i7i8gkkea\nlpFS8jxwk5ldCNFVNTlMYSyw6G+mDiW6Z/jLfei3kuiHxdH4rpj/MbHtJDA8sXyY6E/dkdEu0xbg\nT+IfJKm/g1rZx5pEzqAzdykZ7r47vlvg82ZWRnSXvTuAd/vQTSPR7VXHAT9MXd2STb/ufszMfkh0\nS+D3gJ8nNv8N8JCZtRLN698D/B8zOw68dJbx/IDozoA74ymhI0Q/dETOiS6FlE+N+EqUz7v7Nws9\nFpH+pmkZEZEA6cxdRCRAOnMXEQmQwl1EJEAKdxGRACncRUQCpHAXEQnQ/wdM0TaFl04YAQAAAABJ\nRU5ErkJggg==\n", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%matplotlib inline\n", + "data_pred = pd.DataFrame({'Temperature': np.linspace(start=30, stop=90, num=121), 'Intercept': 1})\n", + "data_pred['Frequency'] = logmodel.predict(data_pred)\n", + "data_pred.plot(x=\"Temperature\",y=\"Frequency\",kind=\"line\",ylim=[0,1])\n", + "plt.scatter(x=data[\"Temperature\"],y=data[\"Frequency\"])\n", + "plt.grid(True)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "hideCode": false, + "hidePrompt": false, + "scrolled": true + }, + "source": [ + "As expected from the initial data, the\n", + "temperature has no significant impact on the probability of failure of the\n", + "O-rings. It will be about 0.2, as in the tests\n", + "where we had a failure of at least one joint. Let's get back\n", + "to the initial dataset to estimate the probability of failure:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.0652173913043\n" + ] + } + ], + "source": [ + "data = pd.read_csv(\"shuttle.csv\")\n", + "print(np.sum(data.Malfunction)/np.sum(data.Count))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This probability is thus about $p=0.065$. Knowing that there is\n", + "a primary and a secondary O-ring on each of the three parts of the\n", + "launcher, the probability of failure of both joints of a launcher\n", + "is $p^2 \\approx 0.00425$. The probability of failure of any one of the\n", + "launchers is $1-(1-p^2)^3 \\approx 1.2%$. That would really be\n", + "bad luck.... Everything is under control, so the takeoff can happen\n", + "tomorrow as planned.\n", + "\n", + "But the next day, the Challenger shuttle exploded and took away\n", + "with her the seven crew members. The public was shocked and in\n", + "the subsequent investigation, the reliability of the\n", + "O-rings was questioned. Beyond the internal communication problems\n", + "of NASA, which have a lot to do with this fiasco, the previous analysis\n", + "includes (at least) a small problem.... Can you find it?\n", + "You are free to modify this analysis and to look at this dataset\n", + "from all angles in order to to explain what's wrong." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "celltoolbar": "Hide code", + "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.6.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/module2/exo5/exo5.Rmd b/module2/exo5/exo5_fr.Rmd similarity index 80% rename from module2/exo5/exo5.Rmd rename to module2/exo5/exo5_fr.Rmd index 3c1d6b557120469e186823bb6be0134db69a9aad..479d7823321976e2d925d00ea599e205bfbd8cc7 100644 --- a/module2/exo5/exo5.Rmd +++ b/module2/exo5/exo5_fr.Rmd @@ -5,7 +5,7 @@ date: "28 juin 2018" output: html_document --- -Le 27 Janvier 1986, veille du décollage de la navette /Challenger/, eu +Le 27 Janvier 1986, veille du décollage de la navette _Challenger_, eu lieu une télé-conférence de trois heures entre les ingénieurs de la Morton Thiokol (constructeur d'un des moteurs) et de la NASA. La discussion portait principalement sur les conséquences de la @@ -93,12 +93,25 @@ plot(tempv,rmv,type="l",ylim=c(0,1)) points(data=data, Malfunction/Count ~ Temperature) ``` -La probabilité d'échec des joints toriques est donc d'environ 0.2 -(comme dans les essais précédents) et comme on pouvait s'attendre au -vu des données initiales, la température n'a pas d'impact notable. La -probabilité que tous les joints toriques dysfonctionnent est de -$0.2^6 \approx 6.4\times10^{-5}$. Tout est sous contrôle, le décollage -peut donc avoir lieu demain comme prévu. +Comme on pouvait s'attendre au vu des données initiales, la +température n'a pas d'impact notable sur la probabilité d'échec des +joints toriques. Elle sera d'environ 0.2, comme dans les essais +précédents où nous il y a eu défaillance d'au moins un joint. Revenons +à l'ensemble des données initiales pour estimer la probabilité de +défaillance d'un joint: + +```{r} +data_full = read.csv("shuttle.csv",header=T) +sum(data_full$Malfunction)/sum(data_full$Count) +``` + +Cette probabilité est donc d'environ $p=0.065$, sachant qu'il existe +un joint primaire un joint secondaire sur chacune des trois parties du +lançeur, la probabilité de défaillance des deux joints d'un lançeur +est de $p^2 \approx 0.00425$. La probabilité de défaillance d'un des +lançeur est donc de $1-(1-p^2)^3 \approx 1.2%$. Ça serait vraiment +pas de chance... Tout est sous contrôle, le décollage peut donc avoir +lieu demain comme prévu. Seulement, le lendemain, la navette Challenger explosera et emportera avec elle ses sept membres d'équipages. L'opinion publique est @@ -109,4 +122,3 @@ fiasco, l'analyse précédente comporte (au moins) un petit problème... Saurez-vous le trouver ? Vous êtes libre de modifier cette analyse et de regarder ce jeu de données sous tous les angles afin d'expliquer ce qui ne va pas. - diff --git a/module2/exo5/exo5.ipynb b/module2/exo5/exo5_fr.ipynb similarity index 99% rename from module2/exo5/exo5.ipynb rename to module2/exo5/exo5_fr.ipynb index 4540ac817ead2bc28bcac65f485d6e83ba009784..b8dba2d37ab1cb8533519fea6bf1bcae9a2a6f67 100644 --- a/module2/exo5/exo5.ipynb +++ b/module2/exo5/exo5_fr.ipynb @@ -709,7 +709,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5rc1" + "version": "3.6.1" } }, "nbformat": 4, diff --git a/module2/exo5/exo5_python-en.org b/module2/exo5/exo5_python_en.org similarity index 99% rename from module2/exo5/exo5_python-en.org rename to module2/exo5/exo5_python_en.org index 8c4c66a12d63e37a92945e5f12bc90e611c724cb..23bfbbe6ceb1705b8ea031dda10fc3c21094e49a 100644 --- a/module2/exo5/exo5_python-en.org +++ b/module2/exo5/exo5_python_en.org @@ -1,6 +1,6 @@ #+TITLE: Analysis of the risk of failure of the O-rings on the Challenger shuttle #+AUTHOR: Arnaud Legrand -#+LANGUAGE: fr +#+LANGUAGE: en #+HTML_HEAD: #+HTML_HEAD: @@ -202,7 +202,7 @@ This probability is thus about $p=0.065$. Knowing that there is a primary and a secondary O-ring on each of the three parts of the launcher, the probability of failure of both joints of a launcher is $p^2 \approx 0.00425$. The probability of failure of any one of the -launchers is $1-(1-p^2)^3 \approximately 1.2%$. That would really be +launchers is $1-(1-p^2)^3 \approx 1.2%$. That would really be bad luck.... Everything is under control, so the takeoff can happen tomorrow as planned. diff --git a/module2/exo5/exo5_python.org b/module2/exo5/exo5_python_fr.org similarity index 100% rename from module2/exo5/exo5_python.org rename to module2/exo5/exo5_python_fr.org