forked from joanby/r-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07-uniforme.Rmd
More file actions
62 lines (45 loc) · 1.06 KB
/
Copy path07-uniforme.Rmd
File metadata and controls
62 lines (45 loc) · 1.06 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
---
title: "Distribución Uniforme"
author: "Curso de Estadística Descriptiva"
date: "7/2/2019"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Distribución Uniforme
Supongamos que $X\sim U([0,1])$ entonces podemos estudiar sus parámetros
## En `R`
```{r}
a = 0
b = 1
x = seq(-0.1, 1.1, 0.1)
plot(x, dunif(x, min = a, max = b))
plot(x, punif(x, a, b), type = "l")
qunif(0.5, a, b)
runif(1000000, a, b) -> data
hist(data)
```
## En `Python`
```{python}
from scipy.stats import uniform
import matplotlib.pyplot as plt
import numpy as np
a = 0
b = 1
loc = a
scale = b-a
fig, ax = plt.subplots(1,1)
rv = uniform(loc = loc, scale = scale)
mean, var, skew, kurt = rv.stats(moments = 'mvsk')
print("Media %f"%mean)
print("Varianza %f"%var)
print("Sesgo %f"%skew)
print("Curtosis %f"%kurt)
x = np.linspace(-0.1, 1.1, 120)
ax.plot(x, rv.pdf(x), 'k-', lw = 2, label = "U(0,1)")
r = rv.rvs(size = 100000)
ax.hist(r, density = True, histtype = "stepfilled", alpha = 0.25)
ax.legend(loc = 'best', frameon = False)
plt.show()
```