Dado1 <- 1:6
Dado2 <- 1:6
X1 = function(){
Resultado_a1 <- sample(Dado1, 1, replace = TRUE) + sample(Dado2, 1, replace = TRUE)
return(Resultado_a1)
}
X1()
## [1] 7
X2 = function(nLanzamientos, cCondición){
Resultado_b1 = array(NA, nLanzamientos)
for (i in 1:nLanzamientos) {
Resultado_b1[i] <- sample(Dado1, 1, replace = TRUE) + sample(Dado2, 1, replace = TRUE)
}
rCondición <- sum(Resultado_b1 == cCondición)
print(paste("Número de Lanzamientos:", nLanzamientos, ", Frecuencia del número", cCondición, ":", rCondición))
}
X2(nLanzamientos = 50, cCondición = 12)
## [1] "Número de Lanzamientos: 50 , Frecuencia del número 12 : 1"
C. Con la función de b. compare los resultados de la simulación para 10000 lanzamientos con los resultados esperados de acuerdo a la probabilidad calculada con el total de combinaciones.
Espacio = expand.grid(Dado1=(1:6),Dado2=(1:6))
y = apply(Espacio,1,sum)
data.frame(Espacio,y)
## Dado1 Dado2 y
## 1 1 1 2
## 2 2 1 3
## 3 3 1 4
## 4 4 1 5
## 5 5 1 6
## 6 6 1 7
## 7 1 2 3
## 8 2 2 4
## 9 3 2 5
## 10 4 2 6
## 11 5 2 7
## 12 6 2 8
## 13 1 3 4
## 14 2 3 5
## 15 3 3 6
## 16 4 3 7
## 17 5 3 8
## 18 6 3 9
## 19 1 4 5
## 20 2 4 6
## 21 3 4 7
## 22 4 4 8
## 23 5 4 9
## 24 6 4 10
## 25 1 5 6
## 26 2 5 7
## 27 3 5 8
## 28 4 5 9
## 29 5 5 10
## 30 6 5 11
## 31 1 6 7
## 32 2 6 8
## 33 3 6 9
## 34 4 6 10
## 35 5 6 11
## 36 6 6 12
prob_teorica = table(y)/36
prob_teorica
## y
## 2 3 4 5 6 7 8
## 0.02777778 0.05555556 0.08333333 0.11111111 0.13888889 0.16666667 0.13888889
## 9 10 11 12
## 0.11111111 0.08333333 0.05555556 0.02777778
plot(2:12,prob_teorica,type = "b")
##Punto 2: Simulación Resultado de la Suma del Lanzamiento de dos Dados
Pob.= sample(x = c(0, 1), size = 1000, replace = TRUE)
Pob.[c(1:100)]
## [1] 0 1 1 0 1 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 1 1 1 1 0 0 1 0 1 1 1 0 0 0 1 0
## [38] 1 1 1 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 0 0 0 1 1 1 1
## [75] 1 0 0 0 1 1 0 0 1 0 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1
b.Crear una función que obtenga una muestra de esa población de a. y calcule el porcentaje de 1.
sum(sample(Pob.,size = 200))/200
## [1] 0.445
c.Repita este proceso una cantidad (mas de 1000 veces) y guarde los porcentajes de cada iteración.
calc_por_uno=function(n_muestra) {
pob=c(rep(x = 1,100),rep(x = 0,900))
return(sum(sample(pob,size = n_muestra))/n_muestra)
}
calc_por_uno(n_muestra = 200)
## [1] 0.095
sapply(rep(200,1000),calc_por_uno)
## [1] 0.120 0.125 0.100 0.110 0.110 0.080 0.090 0.090 0.070 0.105 0.085 0.100
## [13] 0.135 0.110 0.080 0.085 0.070 0.110 0.070 0.125 0.125 0.095 0.085 0.120
## [25] 0.060 0.115 0.095 0.095 0.100 0.090 0.100 0.105 0.085 0.110 0.095 0.085
## [37] 0.125 0.120 0.095 0.085 0.090 0.075 0.095 0.115 0.120 0.085 0.105 0.110
## [49] 0.105 0.110 0.100 0.105 0.100 0.080 0.085 0.060 0.065 0.085 0.150 0.145
## [61] 0.090 0.095 0.130 0.110 0.100 0.130 0.125 0.095 0.090 0.120 0.100 0.100
## [73] 0.065 0.095 0.125 0.090 0.120 0.125 0.100 0.120 0.075 0.065 0.115 0.095
## [85] 0.115 0.100 0.090 0.105 0.110 0.070 0.100 0.090 0.115 0.110 0.090 0.070
## [97] 0.115 0.120 0.090 0.095 0.125 0.110 0.105 0.105 0.080 0.095 0.150 0.100
## [109] 0.100 0.115 0.115 0.090 0.110 0.085 0.110 0.115 0.105 0.090 0.095 0.100
## [121] 0.095 0.110 0.115 0.070 0.100 0.080 0.090 0.110 0.095 0.140 0.095 0.085
## [133] 0.105 0.100 0.080 0.115 0.090 0.105 0.105 0.125 0.075 0.095 0.155 0.120
## [145] 0.080 0.120 0.130 0.065 0.115 0.090 0.070 0.095 0.070 0.100 0.070 0.095
## [157] 0.095 0.100 0.120 0.075 0.080 0.100 0.085 0.100 0.150 0.085 0.065 0.080
## [169] 0.090 0.065 0.105 0.145 0.075 0.095 0.085 0.135 0.120 0.105 0.085 0.090
## [181] 0.115 0.095 0.090 0.080 0.080 0.075 0.070 0.080 0.080 0.110 0.125 0.105
## [193] 0.070 0.140 0.080 0.130 0.085 0.130 0.100 0.095 0.085 0.110 0.090 0.135
## [205] 0.085 0.130 0.090 0.115 0.105 0.080 0.075 0.100 0.080 0.110 0.105 0.095
## [217] 0.085 0.120 0.095 0.115 0.105 0.110 0.120 0.080 0.105 0.125 0.110 0.075
## [229] 0.060 0.085 0.080 0.115 0.120 0.085 0.130 0.105 0.105 0.115 0.125 0.075
## [241] 0.140 0.150 0.095 0.085 0.125 0.090 0.105 0.100 0.095 0.100 0.100 0.095
## [253] 0.090 0.150 0.110 0.120 0.075 0.130 0.080 0.095 0.100 0.085 0.095 0.115
## [265] 0.095 0.105 0.110 0.070 0.105 0.115 0.100 0.130 0.100 0.110 0.100 0.100
## [277] 0.075 0.075 0.095 0.100 0.100 0.090 0.135 0.100 0.120 0.090 0.120 0.100
## [289] 0.095 0.060 0.120 0.105 0.100 0.105 0.140 0.045 0.105 0.120 0.090 0.100
## [301] 0.090 0.120 0.125 0.090 0.090 0.105 0.120 0.140 0.075 0.095 0.095 0.085
## [313] 0.090 0.085 0.090 0.125 0.090 0.065 0.095 0.075 0.090 0.080 0.100 0.080
## [325] 0.070 0.110 0.095 0.090 0.110 0.105 0.120 0.095 0.095 0.105 0.105 0.090
## [337] 0.130 0.080 0.095 0.060 0.120 0.075 0.135 0.080 0.110 0.110 0.110 0.070
## [349] 0.110 0.090 0.110 0.105 0.145 0.130 0.105 0.095 0.065 0.080 0.105 0.085
## [361] 0.110 0.075 0.090 0.055 0.105 0.065 0.105 0.105 0.105 0.100 0.080 0.130
## [373] 0.085 0.130 0.080 0.105 0.125 0.090 0.080 0.110 0.100 0.075 0.135 0.080
## [385] 0.100 0.075 0.110 0.090 0.105 0.100 0.080 0.125 0.095 0.100 0.115 0.060
## [397] 0.090 0.065 0.080 0.075 0.125 0.120 0.140 0.120 0.095 0.135 0.095 0.140
## [409] 0.085 0.115 0.110 0.090 0.135 0.075 0.135 0.095 0.100 0.095 0.095 0.115
## [421] 0.095 0.095 0.120 0.090 0.085 0.125 0.115 0.100 0.075 0.095 0.085 0.120
## [433] 0.120 0.095 0.090 0.085 0.100 0.080 0.095 0.085 0.110 0.085 0.080 0.095
## [445] 0.100 0.090 0.090 0.105 0.110 0.115 0.075 0.080 0.070 0.130 0.110 0.085
## [457] 0.090 0.075 0.105 0.130 0.120 0.090 0.105 0.090 0.130 0.095 0.070 0.085
## [469] 0.130 0.125 0.090 0.090 0.135 0.105 0.105 0.110 0.070 0.110 0.095 0.095
## [481] 0.100 0.090 0.080 0.100 0.090 0.115 0.095 0.130 0.100 0.070 0.095 0.105
## [493] 0.085 0.105 0.055 0.095 0.100 0.125 0.090 0.135 0.110 0.095 0.095 0.095
## [505] 0.090 0.100 0.090 0.080 0.140 0.085 0.100 0.105 0.105 0.080 0.155 0.110
## [517] 0.110 0.100 0.085 0.080 0.115 0.095 0.150 0.110 0.125 0.105 0.095 0.115
## [529] 0.130 0.080 0.120 0.150 0.080 0.070 0.090 0.090 0.110 0.080 0.105 0.135
## [541] 0.085 0.100 0.125 0.115 0.095 0.085 0.125 0.095 0.085 0.130 0.120 0.110
## [553] 0.095 0.100 0.085 0.085 0.090 0.075 0.100 0.090 0.105 0.120 0.085 0.105
## [565] 0.110 0.085 0.100 0.095 0.115 0.070 0.100 0.115 0.105 0.105 0.095 0.105
## [577] 0.140 0.080 0.095 0.095 0.085 0.110 0.120 0.075 0.075 0.095 0.075 0.065
## [589] 0.125 0.105 0.100 0.110 0.115 0.100 0.090 0.090 0.090 0.115 0.125 0.070
## [601] 0.095 0.085 0.115 0.085 0.105 0.090 0.050 0.130 0.105 0.085 0.080 0.105
## [613] 0.115 0.150 0.090 0.080 0.090 0.120 0.125 0.115 0.080 0.090 0.075 0.080
## [625] 0.100 0.085 0.110 0.095 0.120 0.070 0.080 0.125 0.090 0.105 0.115 0.080
## [637] 0.110 0.115 0.075 0.065 0.065 0.130 0.090 0.115 0.135 0.110 0.095 0.090
## [649] 0.115 0.085 0.105 0.095 0.095 0.135 0.065 0.095 0.085 0.110 0.095 0.095
## [661] 0.085 0.090 0.095 0.095 0.090 0.105 0.100 0.105 0.105 0.095 0.115 0.085
## [673] 0.120 0.100 0.130 0.095 0.115 0.105 0.110 0.095 0.095 0.055 0.085 0.110
## [685] 0.130 0.130 0.075 0.120 0.125 0.110 0.085 0.115 0.105 0.115 0.095 0.095
## [697] 0.085 0.085 0.120 0.110 0.110 0.085 0.125 0.135 0.090 0.120 0.045 0.105
## [709] 0.095 0.100 0.095 0.090 0.090 0.085 0.095 0.070 0.120 0.105 0.100 0.095
## [721] 0.110 0.105 0.080 0.095 0.115 0.095 0.080 0.100 0.145 0.065 0.075 0.090
## [733] 0.150 0.080 0.120 0.080 0.145 0.100 0.105 0.100 0.100 0.095 0.105 0.130
## [745] 0.115 0.095 0.095 0.120 0.095 0.105 0.085 0.105 0.095 0.105 0.125 0.095
## [757] 0.090 0.110 0.100 0.100 0.090 0.080 0.115 0.130 0.060 0.105 0.165 0.130
## [769] 0.135 0.095 0.090 0.120 0.100 0.110 0.090 0.085 0.100 0.085 0.115 0.090
## [781] 0.105 0.110 0.085 0.120 0.110 0.095 0.095 0.110 0.100 0.100 0.065 0.125
## [793] 0.085 0.075 0.110 0.065 0.130 0.115 0.065 0.095 0.100 0.110 0.135 0.100
## [805] 0.095 0.100 0.130 0.115 0.090 0.075 0.100 0.140 0.105 0.140 0.095 0.115
## [817] 0.090 0.070 0.085 0.105 0.080 0.115 0.115 0.095 0.075 0.090 0.135 0.095
## [829] 0.090 0.075 0.115 0.095 0.075 0.120 0.095 0.110 0.100 0.120 0.095 0.095
## [841] 0.105 0.095 0.095 0.105 0.120 0.105 0.065 0.110 0.120 0.105 0.100 0.120
## [853] 0.100 0.070 0.135 0.120 0.105 0.105 0.085 0.095 0.080 0.075 0.075 0.115
## [865] 0.110 0.110 0.125 0.120 0.110 0.070 0.115 0.105 0.105 0.100 0.115 0.125
## [877] 0.085 0.070 0.140 0.100 0.090 0.125 0.125 0.115 0.090 0.105 0.105 0.115
## [889] 0.105 0.115 0.115 0.120 0.100 0.100 0.125 0.110 0.100 0.065 0.120 0.075
## [901] 0.095 0.095 0.125 0.095 0.100 0.115 0.075 0.130 0.105 0.110 0.085 0.065
## [913] 0.080 0.075 0.115 0.095 0.100 0.075 0.045 0.085 0.100 0.075 0.100 0.085
## [925] 0.070 0.100 0.105 0.100 0.070 0.085 0.095 0.120 0.065 0.100 0.085 0.060
## [937] 0.095 0.095 0.135 0.130 0.095 0.100 0.130 0.140 0.120 0.105 0.085 0.110
## [949] 0.090 0.100 0.100 0.115 0.090 0.100 0.095 0.100 0.110 0.090 0.145 0.125
## [961] 0.110 0.115 0.130 0.120 0.090 0.080 0.085 0.095 0.130 0.140 0.115 0.120
## [973] 0.090 0.105 0.105 0.115 0.100 0.130 0.120 0.085 0.120 0.110 0.085 0.110
## [985] 0.120 0.110 0.095 0.130 0.110 0.095 0.130 0.095 0.095 0.100 0.100 0.105
## [997] 0.100 0.080 0.085 0.090
porcentajes_muestra=array(NA,1000)
for(i in 1:1000) {
pob=c(rep(x = 1,100),rep(x = 0,900))
porcentajes_muestra[i]=sum(sample(pob,size = 200))/200
}
porcentajes_muestra
## [1] 0.100 0.100 0.105 0.100 0.115 0.065 0.100 0.075 0.085 0.120 0.060 0.110
## [13] 0.100 0.075 0.090 0.070 0.085 0.130 0.105 0.115 0.085 0.100 0.090 0.120
## [25] 0.085 0.080 0.150 0.090 0.105 0.110 0.135 0.115 0.065 0.120 0.100 0.105
## [37] 0.120 0.095 0.125 0.105 0.100 0.100 0.100 0.085 0.095 0.115 0.070 0.075
## [49] 0.100 0.090 0.085 0.080 0.105 0.115 0.100 0.095 0.125 0.075 0.090 0.070
## [61] 0.105 0.115 0.085 0.125 0.080 0.100 0.105 0.120 0.120 0.095 0.100 0.085
## [73] 0.085 0.095 0.080 0.100 0.125 0.065 0.110 0.120 0.075 0.125 0.100 0.110
## [85] 0.125 0.070 0.120 0.095 0.095 0.125 0.105 0.095 0.095 0.135 0.085 0.090
## [97] 0.080 0.085 0.080 0.130 0.065 0.115 0.120 0.110 0.080 0.115 0.120 0.070
## [109] 0.110 0.115 0.105 0.105 0.130 0.075 0.085 0.110 0.100 0.105 0.105 0.085
## [121] 0.085 0.085 0.065 0.090 0.100 0.095 0.105 0.100 0.105 0.095 0.060 0.100
## [133] 0.090 0.090 0.080 0.120 0.125 0.125 0.095 0.100 0.105 0.100 0.100 0.100
## [145] 0.105 0.085 0.115 0.120 0.105 0.115 0.110 0.050 0.125 0.090 0.085 0.100
## [157] 0.105 0.105 0.115 0.090 0.090 0.115 0.105 0.110 0.110 0.130 0.060 0.080
## [169] 0.120 0.140 0.085 0.085 0.095 0.095 0.130 0.080 0.070 0.120 0.110 0.090
## [181] 0.080 0.100 0.095 0.085 0.105 0.110 0.080 0.090 0.085 0.090 0.090 0.110
## [193] 0.100 0.100 0.115 0.105 0.095 0.105 0.110 0.065 0.090 0.085 0.075 0.100
## [205] 0.090 0.135 0.115 0.095 0.095 0.090 0.135 0.085 0.095 0.120 0.115 0.095
## [217] 0.100 0.085 0.105 0.095 0.115 0.085 0.110 0.095 0.065 0.090 0.120 0.070
## [229] 0.095 0.100 0.080 0.130 0.080 0.120 0.125 0.095 0.120 0.125 0.125 0.070
## [241] 0.090 0.110 0.110 0.135 0.090 0.085 0.095 0.115 0.075 0.125 0.090 0.080
## [253] 0.080 0.100 0.080 0.095 0.075 0.130 0.080 0.100 0.115 0.095 0.090 0.115
## [265] 0.090 0.090 0.090 0.090 0.095 0.110 0.105 0.085 0.105 0.110 0.135 0.100
## [277] 0.105 0.115 0.085 0.075 0.120 0.090 0.105 0.080 0.075 0.140 0.115 0.120
## [289] 0.090 0.095 0.095 0.105 0.120 0.115 0.120 0.095 0.100 0.110 0.105 0.115
## [301] 0.105 0.090 0.095 0.090 0.145 0.095 0.105 0.105 0.105 0.095 0.085 0.105
## [313] 0.145 0.130 0.080 0.125 0.120 0.090 0.145 0.125 0.085 0.105 0.085 0.080
## [325] 0.125 0.100 0.115 0.105 0.090 0.135 0.105 0.090 0.160 0.110 0.110 0.115
## [337] 0.070 0.085 0.120 0.065 0.100 0.120 0.105 0.120 0.100 0.085 0.095 0.065
## [349] 0.085 0.120 0.085 0.095 0.100 0.095 0.120 0.105 0.115 0.130 0.105 0.095
## [361] 0.115 0.075 0.125 0.095 0.115 0.070 0.140 0.130 0.105 0.095 0.085 0.075
## [373] 0.115 0.075 0.090 0.090 0.095 0.110 0.075 0.100 0.125 0.090 0.090 0.085
## [385] 0.110 0.105 0.095 0.110 0.100 0.070 0.110 0.100 0.115 0.095 0.100 0.090
## [397] 0.100 0.115 0.095 0.110 0.125 0.135 0.100 0.125 0.065 0.120 0.100 0.080
## [409] 0.090 0.065 0.105 0.150 0.105 0.090 0.115 0.095 0.100 0.080 0.070 0.065
## [421] 0.120 0.120 0.070 0.105 0.090 0.105 0.120 0.115 0.125 0.095 0.105 0.110
## [433] 0.110 0.130 0.100 0.080 0.110 0.080 0.110 0.110 0.095 0.075 0.105 0.095
## [445] 0.075 0.100 0.090 0.105 0.085 0.100 0.055 0.095 0.095 0.105 0.115 0.100
## [457] 0.080 0.100 0.100 0.095 0.075 0.090 0.110 0.075 0.100 0.105 0.110 0.110
## [469] 0.070 0.105 0.090 0.115 0.120 0.105 0.090 0.100 0.075 0.100 0.115 0.100
## [481] 0.100 0.095 0.075 0.095 0.090 0.090 0.085 0.095 0.095 0.080 0.120 0.090
## [493] 0.120 0.140 0.105 0.095 0.115 0.090 0.115 0.095 0.100 0.095 0.065 0.085
## [505] 0.105 0.095 0.105 0.100 0.110 0.100 0.105 0.080 0.110 0.085 0.135 0.125
## [517] 0.125 0.095 0.115 0.115 0.125 0.095 0.135 0.100 0.090 0.080 0.080 0.095
## [529] 0.080 0.075 0.070 0.090 0.115 0.095 0.110 0.110 0.080 0.125 0.155 0.085
## [541] 0.135 0.135 0.135 0.080 0.090 0.070 0.105 0.115 0.130 0.095 0.100 0.110
## [553] 0.090 0.125 0.100 0.115 0.095 0.110 0.090 0.095 0.115 0.110 0.110 0.090
## [565] 0.095 0.115 0.085 0.105 0.095 0.085 0.085 0.095 0.110 0.095 0.100 0.135
## [577] 0.105 0.080 0.060 0.090 0.100 0.100 0.085 0.090 0.090 0.100 0.105 0.110
## [589] 0.080 0.105 0.115 0.100 0.095 0.105 0.090 0.095 0.080 0.055 0.085 0.125
## [601] 0.115 0.085 0.085 0.080 0.120 0.110 0.075 0.090 0.115 0.090 0.110 0.130
## [613] 0.085 0.080 0.130 0.080 0.070 0.115 0.100 0.125 0.090 0.050 0.105 0.140
## [625] 0.115 0.100 0.105 0.115 0.105 0.095 0.105 0.105 0.120 0.085 0.090 0.090
## [637] 0.080 0.085 0.090 0.090 0.120 0.100 0.100 0.080 0.125 0.090 0.100 0.110
## [649] 0.135 0.105 0.120 0.085 0.090 0.105 0.070 0.100 0.055 0.090 0.075 0.105
## [661] 0.090 0.085 0.120 0.100 0.090 0.085 0.105 0.075 0.090 0.075 0.135 0.090
## [673] 0.100 0.085 0.075 0.135 0.065 0.095 0.100 0.105 0.115 0.095 0.110 0.085
## [685] 0.080 0.085 0.075 0.105 0.095 0.105 0.110 0.105 0.080 0.105 0.075 0.135
## [697] 0.090 0.070 0.115 0.130 0.095 0.115 0.095 0.095 0.070 0.120 0.070 0.120
## [709] 0.075 0.110 0.085 0.100 0.085 0.085 0.110 0.120 0.065 0.115 0.085 0.145
## [721] 0.110 0.110 0.135 0.120 0.075 0.110 0.110 0.115 0.135 0.110 0.085 0.085
## [733] 0.115 0.125 0.100 0.055 0.105 0.105 0.065 0.125 0.095 0.115 0.100 0.085
## [745] 0.080 0.105 0.120 0.125 0.080 0.105 0.110 0.095 0.130 0.100 0.115 0.100
## [757] 0.085 0.110 0.095 0.085 0.110 0.095 0.115 0.110 0.105 0.085 0.105 0.105
## [769] 0.060 0.085 0.095 0.105 0.100 0.110 0.090 0.065 0.095 0.105 0.100 0.120
## [781] 0.075 0.105 0.085 0.085 0.090 0.120 0.110 0.105 0.095 0.065 0.120 0.065
## [793] 0.090 0.090 0.115 0.120 0.100 0.070 0.120 0.085 0.110 0.120 0.100 0.115
## [805] 0.085 0.135 0.105 0.095 0.110 0.140 0.130 0.075 0.085 0.105 0.120 0.090
## [817] 0.105 0.115 0.135 0.100 0.100 0.120 0.115 0.065 0.085 0.100 0.080 0.105
## [829] 0.110 0.100 0.120 0.105 0.075 0.135 0.085 0.085 0.095 0.105 0.090 0.115
## [841] 0.100 0.095 0.125 0.125 0.105 0.115 0.110 0.130 0.130 0.095 0.105 0.090
## [853] 0.125 0.130 0.085 0.105 0.120 0.095 0.100 0.120 0.085 0.085 0.115 0.105
## [865] 0.115 0.090 0.115 0.125 0.065 0.135 0.120 0.100 0.085 0.120 0.065 0.115
## [877] 0.095 0.105 0.110 0.075 0.115 0.075 0.135 0.135 0.115 0.110 0.080 0.120
## [889] 0.110 0.090 0.120 0.090 0.110 0.115 0.120 0.095 0.090 0.110 0.075 0.115
## [901] 0.115 0.110 0.090 0.090 0.105 0.075 0.095 0.110 0.095 0.065 0.100 0.070
## [913] 0.110 0.040 0.130 0.110 0.100 0.115 0.095 0.090 0.095 0.100 0.090 0.100
## [925] 0.085 0.090 0.085 0.090 0.095 0.110 0.115 0.100 0.095 0.090 0.110 0.110
## [937] 0.130 0.090 0.125 0.110 0.090 0.075 0.115 0.070 0.100 0.125 0.120 0.105
## [949] 0.090 0.095 0.070 0.115 0.095 0.105 0.100 0.070 0.080 0.120 0.130 0.100
## [961] 0.095 0.100 0.085 0.070 0.105 0.095 0.120 0.100 0.120 0.090 0.105 0.075
## [973] 0.075 0.105 0.120 0.110 0.115 0.085 0.095 0.115 0.065 0.095 0.065 0.075
## [985] 0.100 0.105 0.110 0.115 0.090 0.100 0.095 0.100 0.105 0.115 0.080 0.120
## [997] 0.080 0.100 0.070 0.105
d.Grafique los resultados de estos porcentajes y calcule algunos indicadores descriptivos (compare los resultados con la población generada inicial).
summary(porcentajes_muestra)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0400 0.0900 0.1000 0.1001 0.1150 0.1600
hist(porcentajes_muestra)
Paso 3: Función que Calcula Descriptivos Univariados
library(readxl)
Datos_Rotacion <- read_excel("~/JAVERIANA/Actividad 2/Datos_Rotacion.xlsx")
View(Datos_Rotacion)
vCuantitativa <- data.frame("edad" = cbind(sample(x = c(1:20), size = 1000, replace = TRUE)))
my.function.A = function(df, col){
require(ggplot2)
require(ggpubr)
my.plot1 <- ggplot(data = df, mapping = aes(x = df[, col])) + geom_histogram(bins = 40) + labs(x = "Edad", y = "Frecuencia")
my.plot2 <- ggplot(data = df, mapping = aes(x = df[, col])) + geom_boxplot() + labs(x = "Edad")
my.plot3 <- ggarrange(my.plot1, my.plot2, ncol = 2, nrow = 1)
my.summary <- summary(df[, col])
my.list.A <- list("Gráficos" = my.plot3, "Resumen" = my.summary)
return(my.list.A)
}
my.function.A(df = vCuantitativa, col = "edad")
## Loading required package: ggplot2
## Loading required package: ggpubr
## $Gráficos
##
## $Resumen
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.00 5.00 10.00 10.41 15.00 20.00
variable_cualitativa = data.frame("Viaje de Negocios" = cbind(sample(x = c("Frecuentemente","No_Viaja","Raramente"), size = 1000, replace = TRUE)))
funcion_2 = function(df, col){
require(ggplot2)
require(ggpubr)
plot1 = ggplot(data = df, mapping = aes(x = df[, col])) + geom_histogram(bins = 40) + labs(x = "Viaje de Negocios", y = "Frecuencia")
}
barplot(table(variable_cualitativa), col = c("lightblue","pink","yellow"),
main = "Diagrama de barras de las frecuencias absolutas de\n la variable \"Viaje\"")