-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_distributions.Rmd
130 lines (101 loc) · 2.05 KB
/
model_distributions.Rmd
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
---
title: "Manipulation des distributions"
author: "State of the R"
date: "24-28/08/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(distributional)
library(ggplot2)
theme_set(theme_minimal())
```
# Utilisation basique
Création d'une loi normale
```{r}
dn <- dist_normal(mu = 5, sigma = 2)
dn
class(dn)
```
Quelques quantités d'intérêt
```{r}
list(mean = mean(dn), median = median(dn), variance = variance(dn),
skewness = skewness(dn), kurtosis = kurtosis(dn))
```
Courbes
```{r, warning=FALSE}
autoplot(dn)
```
Intervalles
```{r}
hilo(dn) # intervalle de confiance
hdr(dn) # intervalle du ou des modes
```
Échantillonage
```{r}
sample <- generate(dn, times = 10)
sample
likelihood(dn, sample)
```
```{r}
cdf(dn, 5)
quantile(dn, 0.5)
```
Calculs
```{r}
2 * dn - 5
dn ^ 2 # ne connait pas
```
# Vecteur de distribution
```{r}
dchi <- dist_chisq(df = 5)
dt <- dist_student_t(df = 10)
dm <- dist_mixture(dt, dn, weights = c(0.6, 0.4))
dvec <- c(dn, dchi, dt, dm)
dvec
autoplot(dvec)
mean(dvec)
variance(dvec)
hilo(dvec, size = 66)
cdf(dvec, 5)
```
# Graphiques
```{r}
library(ggdist)
df <- data.frame(name = factor(c("N(5,4)", "\u1d6a²(5)", "t(10, 0, 1)", "Mixture"),
levels = c("N(5,4)", "\u1d6a²(5)", "t(10, 0, 1)", "Mixture")),
dist = dvec)
df
ggplot(df) +
aes(y = name, dist = dist, fill = name) +
stat_dist_halfeye(show.legend = FALSE, .width = c(0.66, 0.95)) +
labs(x = NULL, y = NULL)
ggplot(df) +
aes(y = name, dist = dist, fill = name) +
stat_dist_gradientinterval(show.legend = FALSE) +
labs(x = NULL, y = NULL)
ggplot(df) +
aes(y = name, dist = dist, fill = name) +
stat_dist_dots(quantiles = 150, show.legend = FALSE) +
labs(x = NULL, y = NULL)
```
# Lois discretes
```{r}
dp <- dist_poisson(4)
dp
mean(dp)
generate(dp, 10)
```
Loi inflatée
```{r}
dpi <- dist_inflated(dp, 0.5, x = 0)
dpi
mean(dpi)
generate(dpi, 10)
```
# Distribution disponibles
```{r}
ls("package:distributional", pattern = "^dist_")
```