mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-14 18:59:59 +01:00
Add exo 2
This commit is contained in:
@@ -16,12 +16,32 @@ qqplot(x, rexp(n, rate = 2))
|
||||
```{r}
|
||||
lambda <- 1.5
|
||||
n <- 10000
|
||||
d <- 10
|
||||
S <- numeric(n)
|
||||
for (i in 1:n) {
|
||||
u <- runif(10)
|
||||
u <- runif(d)
|
||||
x <- -1/lambda * log(1-u)
|
||||
S[i] <- sum(x)
|
||||
}
|
||||
hist(S, freq = FALSE, breaks = 50)
|
||||
curve(dgamma(x, shape = 10, rate = lambda), add = TRUE, col = "red")
|
||||
curve(dgamma(x, shape = d, rate = lambda), add = TRUE, col = "red")
|
||||
```
|
||||
|
||||
### Question 3
|
||||
```{r}
|
||||
lambda <- 4
|
||||
n <- 10000
|
||||
X <- numeric(n)
|
||||
p <- 1
|
||||
for (i in 1:n) {
|
||||
S <- -1/lambda * log(1-runif(1))
|
||||
while (S <= 1) {
|
||||
S <- x - 1/lambda * log(1-runif(1))
|
||||
p <- p+1
|
||||
}
|
||||
X[i] <- p
|
||||
p <- 1
|
||||
}
|
||||
hist(X, freq = FALSE, breaks = 50)
|
||||
curve(dpois(x, lambda), add = TRUE, col = "red")
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user