-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_Tarea 2.R
89 lines (72 loc) · 2.26 KB
/
5_Tarea 2.R
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
# En esta ayudantia graficaremos las densidades normal, gamma
# y exponencial con los parametros obtenidos con los datos mediante
# el metodo de estimadores de momentos
# Datos
X <- c(40, 62, 69, 77, 83, 88, 94, 101, 109, 115,
123, 125, 128, 136, 137, 152, 152, 153, 160, 165)
n <- length(X)
# 1. Estadisticas descriptivas --------------------------------
min <- min(X)
max <- max(X)
med <- mean(X)
medg <- exp(mean(log(X)))
medn <- median(X)
var <- (1/n)*(sum((X-mean(X))^2))
des <- sqrt(var)
# 2. Estimadores distribucion normal ----------------------
mu <- med
sig <- var
# 3. Estimadores distribucion gamma ----------------------
alp <- (med^2)/var # shape
bet <- var/med # scale
mug <- med
# 4. Estimadores distribucion exponencial ---------------------
the <- med # 1/rate
# 5. Grafica de distribuciones ------------------------
fnorm <- function(x){
return(dnorm(x, mu, des))
}
fgamma <- function(x){
return(dgamma(x, shape = alp, scale = bet))
}
fexp <- function(x){
return(dexp(x, rate = 1/the))
}
y <- rep(0, 20)
plot(fnorm, # funcion
ylim = c(0, 0.012), # Eje Y desde 0 hasta 1
xlim = c(min, max),# Eje X desde -4 hasta 4
lwd = 2, # grosor
col = 'blue', #color
main = 'Densidad normal, gamma y exponencial', # titulo
ylab = expression(d(x)), # etiqueta eje y
xlab = expression(x)) # etiqueta eje x
par(new=TRUE)
plot(fgamma, # funcion
ylim = c(0, 0.012), # Eje Y desde 0 hasta 1
xlim = c(min, max), # Eje X desde -4 hasta 4
lwd = 2, # grosor
col = 'green', #color
main = '', # titulo
ylab = '', # etiqueta eje y
xlab = '',
axes = FALSE) # etiqueta eje x
par(new=TRUE)
plot(fexp, # funcion
ylim = c(0, 0.012), # Eje Y desde 0 hasta 1
xlim = c(min, max), # Eje X desde -4 hasta 4
lwd = 2, # grosor
col = 'red', #color
main = '', # titulo
ylab = '', # etiqueta eje y
xlab = '',
axes = FALSE) # etiqueta eje x
par(new=TRUE)
plot(X, y, # funcion
ylim = c(0, 0.012), # Eje Y desde 0 hasta 1
xlim = c(min, max), # Eje X desde -4 hasta 4
main = '', # titulo
ylab = '', # etiqueta eje y
xlab = '',
pch = 4,
axes = FALSE) # etiqueta eje