-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChapter2.Rmd
More file actions
170 lines (98 loc) · 2.49 KB
/
Chapter2.Rmd
File metadata and controls
170 lines (98 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
---
title: "Chapter 2: Discrete random variables"
output: html_notebook
---
# Binomial Distribution
* A binomial experiment consists of a fixed number of $n$ trials.
* Each trial has two possible outcomes: success, failure.
* The probability of success is denoted by $p,\:0\leq p\leq 1$.
* The probability of failure is $1-p$.
* The trials are assumed independent:
* the outcome of one trial does not affect the outcome probability of any other trial.
```{r}
n=10 # Sample size
p=.5 # probability of success
x=0:n # Possible values
round(dbinom(x,n,p),4)
choose(10,6)
210*(0.5)^4*(0.5)^6
.8^10
dbinom(0,10,0.2)
45*(.2)^2*(.8)^8
choose(10,2)*(.2)^2*(.8)^8
dbinom(2,10,.2)
sum(dbinom(0:4,10,.2))
pbinom(4,10,.2)
library(formattable)
dbinom(2,10,.2)
percent(dbinom(2,10,.2))
```
```{r}
B<-as.table(dbinom(0:10,10,.2))
B
names(B)<-0:10
B
plot(B,col="red",main="Bar plot for binomial PDF",xlab="Number of correct answers",ylab="Probability")
```
```{r}
set.seed(123)
res<-rbinom(10000,10,.2)
head(res,10)
mean(res)
round(dbinom(0:10,10,.2),4)
table(res)
sum((0:10)*dbinom(0:10,10,.2))
(0:10)%*%dbinom(0:10,10,.2)
var(res)
mean((res-mean(res))^2)
(0:10-2)^2%*%dbinom(0:10,10,.2)
10*.2*.8
```
## Exercice 7.84
On a $n=10$ er $p=0.3$.
a. Calculer $\Pr(X=3)$.
```{r}
round(dbinom(3,10,0.3),4)
```
b. Calculer $\Pr(X=5)$.
```{r}
round(dbinom(5,10,0.3),4)
```
c. Calculer $\Pr(X=8)$.
```{r}
round(dbinom(8,10,0.3),4)
```
## Obtenir les 3 résulats d'un coup.
```{r}
round(dbinom(c(3,5,8),10,0.3),4)
```
## Executer le Chunk en ligne de manière transparente
a. Calculer $\Pr(X=3)$. On trouve $\Pr(X=3)=$ `r round(dbinom(3,10,0.3),4)`.
## Exercice 7.92
```{r}
dbinom(1,4,1/4)
dbinom(2,8,1/4)
dbinom(3,12,1/4)
```
Taper un code en ligne. Un exemple simple `r 112+234`.
## 7.101 b.
$$E(X)=100\times \frac{244}{495}$$
On trouve `r round(100*244/495,0)`. Il gagne environ en moyenne `r round(100*244/495,0)` parties pour 100 parties jouées.
## Exercice 7.138
Soit $X$ le nombre de faux-positifs pour 10 ans de mammographie. On a $X$ suit une loi $\mathcal{B}(10,p)$ où $p$ est inconnu. On sait que $\Pr(X\geq 1)=0.6$. On doit trouver $p$.
On a $$Pr(X \geq 1) = 1 - Pr(X=0)$$ Soit :
$$
1-(1-p)^{10}=0.60.
$$
Cela revient à résoudre l'équation suivante :
$$
(1-p)^{10}=0.4,
$$
qui donne
$$
1-p = 0.4^{1/10}
$$.
Ainsi,
$$p = 1 - 0.4^{1/10}
$$
Chaque année la probabilité qu'une femme qui passe une mamographie obtienne un faux positif s'élève à `r percent(1 - 0.4^(1/10),1)`.