Commit 45b8372b authored by Victor-M-Gomes's avatar Victor-M-Gomes

module2 exo5

parent 6509bb73
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2020-04-29 mer. 16:49 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Analysis of the risk of failure of the O-rings on the Challenger shuttle</title>
<meta name="generator" content="Org mode" />
<meta name="author" content="Arnaud Legrand" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-hledger:before { content: 'hledger'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.equation-container {
display: table;
text-align: center;
width: 100%;
}
.equation {
vertical-align: middle;
}
.equation-label {
display: table-cell;
text-align: right;
vertical-align: middle;
}
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
</style>
<link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
<link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
<script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
<script type="text/javascript">
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&amp;dn=gpl-3.0.txt GPL-v3-or-Later
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
// @license-end
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
displayAlign: "center",
displayIndent: "0em",
"HTML-CSS": { scale: 100,
linebreaks: { automatic: "false" },
webFont: "TeX"
},
SVG: {scale: 100,
linebreaks: { automatic: "false" },
font: "TeX"},
NativeMML: {scale: 100},
TeX: { equationNumbers: {autoNumber: "AMS"},
MultLineWidth: "85%",
TagSide: "right",
TagIndent: ".8em"
}
});
</script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
</head>
<body>
<div id="content">
<h1 class="title">Analysis of the risk of failure of the O-rings on the Challenger shuttle</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#orgbde8328">1. Loading the data</a></li>
<li><a href="#org533075d">2. Graphical inspection</a></li>
<li><a href="#org0916888">3. Estimation of the temperature influence</a></li>
<li><a href="#org3a49c85">4. Estimation of the probability of O-ring malfunction</a></li>
</ul>
</div>
</div>
<p>
On January 27, 1986, the day before the takeoff of the shuttle <i>Challenger</i>,
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 a 31°F (just below
0°C) temperature, at take-off, in 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.
</p>
<p>
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.
</p>
<div id="outline-container-orgbde8328" class="outline-2">
<h2 id="orgbde8328"><span class="section-number-2">1</span> Loading the data</h2>
<div class="outline-text-2" id="text-1">
<p>
We start by loading this data:
</p>
<div class="org-src-container">
<pre class="src src-python"><span style="color: #51afef;">import</span> numpy <span style="color: #51afef;">as</span> np
<span style="color: #51afef;">import</span> pandas <span style="color: #51afef;">as</span> pd
<span style="color: #dcaeea;">data</span> = pd.read_csv(<span style="color: #98be65;">"shuttle.csv"</span>)
data
</pre>
</div>
<pre class="example">
Date Count Temperature Pressure Malfunction
0 4/12/81 6 66 50 0
1 11/12/81 6 70 50 1
2 3/22/82 6 69 50 0
3 11/11/82 6 68 50 0
4 4/04/83 6 67 50 0
5 6/18/82 6 72 50 0
6 8/30/83 6 73 100 0
7 11/28/83 6 70 100 0
8 2/03/84 6 57 200 1
9 4/06/84 6 63 200 1
10 8/30/84 6 70 200 1
11 10/05/84 6 78 200 0
12 11/08/84 6 67 200 0
13 1/24/85 6 53 200 2
14 4/12/85 6 67 200 0
15 4/29/85 6 75 200 0
16 6/17/85 6 70 200 0
17 7/29/85 6 81 200 0
18 8/27/85 6 76 200 0
19 10/03/85 6 79 200 0
20 10/30/85 6 75 200 2
21 11/26/85 6 76 200 0
22 1/12/86 6 58 200 1
</pre>
<p>
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.
</p>
</div>
</div>
<div id="outline-container-org533075d" class="outline-2">
<h2 id="org533075d"><span class="section-number-2">2</span> Graphical inspection</h2>
<div class="outline-text-2" id="text-2">
<p>
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.
</p>
<div class="org-src-container">
<pre class="src src-python"><span style="color: #dcaeea;">data</span> = data[data.Malfunction&gt;<span style="color: #da8548; font-weight: bold;">0</span>]
data
</pre>
</div>
<pre class="example">
Date Count Temperature Pressure Malfunction
1 11/12/81 6 70 50 1
8 2/03/84 6 57 200 1
9 4/06/84 6 63 200 1
10 8/30/84 6 70 200 1
13 1/24/85 6 53 200 2
20 10/30/85 6 75 200 2
22 1/12/86 6 58 200 1
</pre>
<p>
We have a high temperature variability but
the pressure is almost always 200, which should
simplify the analysis.
</p>
<p>
How does the frequency of failure vary with temperature?
</p>
<div class="org-src-container">
<pre class="src src-python"><span style="color: #51afef;">import</span> matplotlib.pyplot <span style="color: #51afef;">as</span> plt
plt.clf()
<span style="color: #dcaeea;">data</span>[<span style="color: #98be65;">"Frequency"</span>]=data.Malfunction/data.Count
data.plot(x=<span style="color: #98be65;">"Temperature"</span>,y=<span style="color: #98be65;">"Frequency"</span>,kind=<span style="color: #98be65;">"scatter"</span>,ylim=[<span style="color: #da8548; font-weight: bold;">0</span>,<span style="color: #da8548; font-weight: bold;">1</span>])
plt.grid(<span style="color: #a9a1e1;">True</span>)
plt.savefig(matplot_lib_filename)
<span style="color: #51afef;">print</span>(matplot_lib_filename)
</pre>
</div>
<div class="figure">
<p><img src="freq_temp_python.png" alt="freq_temp_python.png" />
</p>
</div>
<p>
At first glance, the dependence does not look very important, but let&rsquo;s try to
estimate the impact of temperature \(t\) on the probability of O-ring malfunction.
</p>
</div>
</div>
<div id="outline-container-org0916888" class="outline-2">
<h2 id="org0916888"><span class="section-number-2">3</span> Estimation of the temperature influence</h2>
<div class="outline-text-2" id="text-3">
<p>
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.
</p>
<div class="org-src-container">
<pre class="src src-python"><span style="color: #51afef;">import</span> statsmodels.api <span style="color: #51afef;">as</span> sm
<span style="color: #dcaeea;">data</span>[<span style="color: #98be65;">"Success"</span>]=data.Count-data.Malfunction
<span style="color: #dcaeea;">data</span>[<span style="color: #98be65;">"Intercept"</span>]=<span style="color: #da8548; font-weight: bold;">1</span>
<span style="color: #5B6268;"># </span><span style="color: #5B6268;">logit_model=sm.Logit(data["Frequency"],data[["Intercept","Temperature"]]).fit() </span>
<span style="color: #dcaeea;">logmodel</span>=sm.GLM(data[<span style="color: #98be65;">'Frequency'</span>], data[[<span style="color: #98be65;">'Intercept'</span>,<span style="color: #98be65;">'Temperature'</span>]], family=sm.families.Binomial(sm.families.links.logit)).fit()
logmodel.summary()
</pre>
</div>
<pre class="example">
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.0000
Method: IRLS Log-Likelihood: -2.5250
Date: mer., 29 avril 2020 Deviance: 0.22231
Time: 16:49:18 Pearson chi2: 0.236
No. Iterations: 4
Covariance Type: nonrobust
===============================================================================
coef std err z P&gt;|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
===============================================================================
</pre>
<p>
The most likely estimator of the temperature parameter is 0.0014
and the standard error of this estimator is 0.122, in other words we
cannot distinguish any particular impact and we must take our
estimates with caution.
</p>
</div>
</div>
<div id="outline-container-org3a49c85" class="outline-2">
<h2 id="org3a49c85"><span class="section-number-2">4</span> Estimation of the probability of O-ring malfunction</h2>
<div class="outline-text-2" id="text-4">
<p>
The expected temperature on the take-off day is 31°F. Let&rsquo;s try to
estimate the probability of O-ring malfunction at
this temperature from the model we just built:
</p>
<div class="org-src-container">
<pre class="src src-python"><span style="color: #51afef;">import</span> matplotlib.pyplot <span style="color: #51afef;">as</span> plt
<span style="color: #dcaeea;">data_pred</span> = pd.DataFrame({<span style="color: #98be65;">'Temperature'</span>: np.linspace(start=<span style="color: #da8548; font-weight: bold;">30</span>, stop=<span style="color: #da8548; font-weight: bold;">90</span>, num=<span style="color: #da8548; font-weight: bold;">121</span>), <span style="color: #98be65;">'Intercept'</span>: <span style="color: #da8548; font-weight: bold;">1</span>})
<span style="color: #dcaeea;">data_pred</span>[<span style="color: #98be65;">'Frequency'</span>] = logmodel.predict(data_pred[[<span style="color: #98be65;">'Intercept'</span>,<span style="color: #98be65;">'Temperature'</span>]])
data_pred.plot(x=<span style="color: #98be65;">"Temperature"</span>,y=<span style="color: #98be65;">"Frequency"</span>,kind=<span style="color: #98be65;">"line"</span>,ylim=[<span style="color: #da8548; font-weight: bold;">0</span>,<span style="color: #da8548; font-weight: bold;">1</span>])
plt.scatter(x=data[<span style="color: #98be65;">"Temperature"</span>],y=data[<span style="color: #98be65;">"Frequency"</span>])
plt.grid(<span style="color: #a9a1e1;">True</span>)
plt.savefig(matplot_lib_filename)
<span style="color: #51afef;">print</span>(matplot_lib_filename)
</pre>
</div>
<div class="figure">
<p><img src="proba_estimate_python.png" alt="proba_estimate_python.png" />
</p>
</div>
<p>
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&rsquo;s get back to the initial dataset to estimate the probability of failure:
</p>
<div class="org-src-container">
<pre class="src src-python"><span style="color: #dcaeea;">data</span> = pd.read_csv(<span style="color: #98be65;">"shuttle.csv"</span>)
<span style="color: #51afef;">print</span>(np.<span style="color: #c678dd;">sum</span>(data.Malfunction)/np.<span style="color: #c678dd;">sum</span>(data.Count))
</pre>
</div>
<pre class="example">
0.06521739130434782
</pre>
<p>
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&#x2026;. Everything is under control, so the takeoff can happen
tomorrow as planned.
</p>
<p>
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&#x2026;. Can you find it?
You are free to modify this analysis and to look at this dataset
from all angles in order to explain what&rsquo;s wrong.
</p>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: Arnaud Legrand</p>
<p class="date">Created: 2020-04-29 mer. 16:49</p>
</div>
</body>
</html>
......@@ -14,12 +14,12 @@
# #+PROPERTY: header-args :session :exports both
On January 27, 1986, the day before the takeoff of the shuttle /Challenger/, had
On January 27, 1986, the day before the takeoff of the shuttle /Challenger/,
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
discussion focused on the consequences of a 31°F (just below
0°C) temperature, at take-off, in 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.
......@@ -79,19 +79,37 @@ 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 python :results value :session *python* :exports both
data = data[data.Malfunction>0]
#data = data[data.Malfunction>0]
data
#+end_src
#+RESULTS:
: Date Count Temperature Pressure Malfunction
: 1 11/12/81 6 70 50 1
: 8 2/03/84 6 57 200 1
: 9 4/06/84 6 63 200 1
: 10 8/30/84 6 70 200 1
: 13 1/24/85 6 53 200 2
: 20 10/30/85 6 75 200 2
: 22 1/12/86 6 58 200 1
#+begin_example
Date Count Temperature Pressure Malfunction
0 4/12/81 6 66 50 0
1 11/12/81 6 70 50 1
2 3/22/82 6 69 50 0
3 11/11/82 6 68 50 0
4 4/04/83 6 67 50 0
5 6/18/82 6 72 50 0
6 8/30/83 6 73 100 0
7 11/28/83 6 70 100 0
8 2/03/84 6 57 200 1
9 4/06/84 6 63 200 1
10 8/30/84 6 70 200 1
11 10/05/84 6 78 200 0
12 11/08/84 6 67 200 0
13 1/24/85 6 53 200 2
14 4/12/85 6 67 200 0
15 4/29/85 6 75 200 0
16 6/17/85 6 70 200 0
17 7/29/85 6 81 200 0
18 8/27/85 6 76 200 0
19 10/03/85 6 79 200 0
20 10/30/85 6 75 200 2
21 11/26/85 6 76 200 0
22 1/12/86 6 58 200 1
#+end_example
We have a high temperature variability but
the pressure is almost always 200, which should
......@@ -133,29 +151,31 @@ data["Success"]=data.Count-data.Malfunction
data["Intercept"]=1
# logit_model=sm.Logit(data["Frequency"],data[["Intercept","Temperature"]]).fit()
#logit_model=sm.Logit(data['Frequency'],data[['Intercept','Temperature']]).fit()
logmodel=sm.GLM(data['Frequency'], data[['Intercept','Temperature']], family=sm.families.Binomial(sm.families.links.logit)).fit()
logmodel.summary()
#logit_model.summary()
#+end_src
#+RESULTS:
#+begin_example
Generalized Linear Model Regression Results
==============================================================================
Dep. Variable: Frequency No. Observations: 7
Model: GLM Df Residuals: 5
===============================================================================
Dep. Variable: Frequency No. Observations: 23
Model: GLM Df Residuals: 21
Model Family: Binomial Df Model: 1
Link Function: logit Scale: 1.0
Method: IRLS Log-Likelihood: -3.6370
Date: Fri, 20 Jul 2018 Deviance: 3.3763
Time: 16:56:08 Pearson chi2: 0.236
No. Iterations: 5
Link Function: logit Scale: 1.0000
Method: IRLS Log-Likelihood: -3.9210
Date: mer., 29 avril 2020 Deviance: 3.0144
Time: 20:57:18 Pearson chi2: 5.00
No. Iterations: 6
Covariance Type: nonrobust
===============================================================================
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
Intercept 5.0850 7.477 0.680 0.496 -9.570 19.740
Temperature -0.1156 0.115 -1.004 0.316 -0.341 0.110
===============================================================================
#+end_example
......@@ -185,6 +205,7 @@ print(matplot_lib_filename)
#+RESULTS:
[[file:proba_estimate_python.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
......@@ -193,10 +214,18 @@ where we had a failure of at least one joint. Let's get back to the initial data
#+begin_src python :results output :session *python* :exports both
data = pd.read_csv("shuttle.csv")
print(np.sum(data.Malfunction)/np.sum(data.Count))
print(np.sum(data.Count))
pfailure = np.sum(data.Malfunction)/23
print(1-(1-0.39**2)**3)
#+end_src
#+RESULTS:
: 0.06521739130434782
: 138
: Probability of failure 0.391304347826087
: Probability failure both joints: 0.15311909262759926
: 0.010869565217391304
: 0.39041551376100003
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
......@@ -213,5 +242,4 @@ 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.
from all angles in order to explain what's wrong.
module2/exo5/freq_temp_python.png

12.3 KB | W: | H:

module2/exo5/freq_temp_python.png

13 KB | W: | H:

module2/exo5/freq_temp_python.png
module2/exo5/freq_temp_python.png
module2/exo5/freq_temp_python.png
module2/exo5/freq_temp_python.png
  • 2-up
  • Swipe
  • Onion skin
module2/exo5/proba_estimate_python.png

14.3 KB | W: | H:

module2/exo5/proba_estimate_python.png

21.9 KB | W: | H:

module2/exo5/proba_estimate_python.png
module2/exo5/proba_estimate_python.png
module2/exo5/proba_estimate_python.png
module2/exo5/proba_estimate_python.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment