El método de la transformada inversa es una técnica ampliamente utilizada en simulación y análisis de sistemas estocásticos para generar variables aleatorias con una distribución de probabilidad especificada. Este método se basa en la inversión de la función de distribución acumulativa (FDA) de la variable aleatoria objetivo. Es especialmente útil debido a su simplicidad conceptual y su aplicabilidad en diversas distribuciones.
a <- 317
c <- 15
m <- 571
X_n <- 41 # semilla
random.number<-numeric(100) # vector numérico de longitud 50
for (i in 1:50)
{X_n<-(a*X_n+c)%%m
random.number[i]<-X_n/m # números en el intervalo [0,1]
}
random.number
## [1] 0.78809107 0.85113835 0.83712785 0.39579685 0.49387040 0.58318739
## [7] 0.89667250 0.27145359 0.07705779 0.45359019 0.81436077 0.17863398
## [13] 0.65323993 0.10332750 0.78108581 0.63047285 0.88616462 0.94045534
## [19] 0.15061296 0.77057793 0.29947461 0.95971979 0.25744308 0.63572680
## [25] 0.55166375 0.90367776 0.49211909 0.02802102 0.90893170 0.15761821
## [31] 0.99124343 0.25043783 0.41506130 0.60070053 0.44833625 0.14886165
## [37] 0.21541156 0.31173380 0.84588441 0.17162872 0.43257443 0.15236427
## [43] 0.32574431 0.28721541 0.07355517 0.34325744 0.83887916 0.95096322
## [49] 0.48161121 0.69702277 0.00000000 0.00000000 0.00000000 0.00000000
## [55] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## [61] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## [67] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## [73] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## [79] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## [85] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## [91] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## [97] 0.00000000 0.00000000 0.00000000 0.00000000
# generando una variable exponencial con beta = 3
x <- -3*log(1-random.number)
round(x,1) # redondeando a una cifra decimal
## [1] 4.7 5.7 5.4 1.5 2.0 2.6 6.8 1.0 0.2 1.8 5.1 0.6 3.2 0.3 4.6
## [16] 3.0 6.5 8.5 0.5 4.4 1.1 9.6 0.9 3.0 2.4 7.0 2.0 0.1 7.2 0.5
## [31] 14.2 0.9 1.6 2.8 1.8 0.5 0.7 1.1 5.6 0.6 1.7 0.5 1.2 1.0 0.2
## [46] 1.3 5.5 9.0 2.0 3.6 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
## [61] 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
## [76] 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
## [91] 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
data.frame(1:length(random.number),random.number,round(x,1))
## X1.length.random.number. random.number round.x..1.
## 1 1 0.78809107 4.7
## 2 2 0.85113835 5.7
## 3 3 0.83712785 5.4
## 4 4 0.39579685 1.5
## 5 5 0.49387040 2.0
## 6 6 0.58318739 2.6
## 7 7 0.89667250 6.8
## 8 8 0.27145359 1.0
## 9 9 0.07705779 0.2
## 10 10 0.45359019 1.8
## 11 11 0.81436077 5.1
## 12 12 0.17863398 0.6
## 13 13 0.65323993 3.2
## 14 14 0.10332750 0.3
## 15 15 0.78108581 4.6
## 16 16 0.63047285 3.0
## 17 17 0.88616462 6.5
## 18 18 0.94045534 8.5
## 19 19 0.15061296 0.5
## 20 20 0.77057793 4.4
## 21 21 0.29947461 1.1
## 22 22 0.95971979 9.6
## 23 23 0.25744308 0.9
## 24 24 0.63572680 3.0
## 25 25 0.55166375 2.4
## 26 26 0.90367776 7.0
## 27 27 0.49211909 2.0
## 28 28 0.02802102 0.1
## 29 29 0.90893170 7.2
## 30 30 0.15761821 0.5
## 31 31 0.99124343 14.2
## 32 32 0.25043783 0.9
## 33 33 0.41506130 1.6
## 34 34 0.60070053 2.8
## 35 35 0.44833625 1.8
## 36 36 0.14886165 0.5
## 37 37 0.21541156 0.7
## 38 38 0.31173380 1.1
## 39 39 0.84588441 5.6
## 40 40 0.17162872 0.6
## 41 41 0.43257443 1.7
## 42 42 0.15236427 0.5
## 43 43 0.32574431 1.2
## 44 44 0.28721541 1.0
## 45 45 0.07355517 0.2
## 46 46 0.34325744 1.3
## 47 47 0.83887916 5.5
## 48 48 0.95096322 9.0
## 49 49 0.48161121 2.0
## 50 50 0.69702277 3.6
## 51 51 0.00000000 0.0
## 52 52 0.00000000 0.0
## 53 53 0.00000000 0.0
## 54 54 0.00000000 0.0
## 55 55 0.00000000 0.0
## 56 56 0.00000000 0.0
## 57 57 0.00000000 0.0
## 58 58 0.00000000 0.0
## 59 59 0.00000000 0.0
## 60 60 0.00000000 0.0
## 61 61 0.00000000 0.0
## 62 62 0.00000000 0.0
## 63 63 0.00000000 0.0
## 64 64 0.00000000 0.0
## 65 65 0.00000000 0.0
## 66 66 0.00000000 0.0
## 67 67 0.00000000 0.0
## 68 68 0.00000000 0.0
## 69 69 0.00000000 0.0
## 70 70 0.00000000 0.0
## 71 71 0.00000000 0.0
## 72 72 0.00000000 0.0
## 73 73 0.00000000 0.0
## 74 74 0.00000000 0.0
## 75 75 0.00000000 0.0
## 76 76 0.00000000 0.0
## 77 77 0.00000000 0.0
## 78 78 0.00000000 0.0
## 79 79 0.00000000 0.0
## 80 80 0.00000000 0.0
## 81 81 0.00000000 0.0
## 82 82 0.00000000 0.0
## 83 83 0.00000000 0.0
## 84 84 0.00000000 0.0
## 85 85 0.00000000 0.0
## 86 86 0.00000000 0.0
## 87 87 0.00000000 0.0
## 88 88 0.00000000 0.0
## 89 89 0.00000000 0.0
## 90 90 0.00000000 0.0
## 91 91 0.00000000 0.0
## 92 92 0.00000000 0.0
## 93 93 0.00000000 0.0
## 94 94 0.00000000 0.0
## 95 95 0.00000000 0.0
## 96 96 0.00000000 0.0
## 97 97 0.00000000 0.0
## 98 98 0.00000000 0.0
## 99 99 0.00000000 0.0
## 100 100 0.00000000 0.0
hist(x, breaks = 20, probability = TRUE, col = "lightblue", ylim=c(0,0.35), main = "Distribución Exponencial (beta = 3)", xlab = "Valor de X")
# Añadimos la función de densidad teórica de la distribución exponencial
curve(dexp(x,rate=1/3), col = "red", lwd = 2, add = TRUE)
# Generar 100 variables aleatorias uniformes entre 0 y 1
uniform_random_01 <- runif(100, min = 0, max = 1)
uniform_random_01
## [1] 0.619882363 0.323732203 0.300133074 0.787789602 0.921448253 0.043339634
## [7] 0.732819889 0.464535113 0.970584498 0.066985365 0.631418594 0.746799193
## [13] 0.928053718 0.966721257 0.594384422 0.579822293 0.082861879 0.193074166
## [19] 0.985569753 0.703140230 0.193542530 0.933014924 0.756922189 0.031245106
## [25] 0.189919535 0.376539164 0.438520133 0.975377834 0.345972788 0.698357597
## [31] 0.355340456 0.949608657 0.189395176 0.858386497 0.279979808 0.094969552
## [37] 0.379023801 0.629371662 0.088725904 0.033070486 0.828106014 0.866706264
## [43] 0.710997756 0.139201850 0.685865383 0.975828604 0.763972880 0.557312307
## [49] 0.627408935 0.497582772 0.042698772 0.498779508 0.430408906 0.412296167
## [55] 0.613186000 0.426579611 0.531891458 0.780823402 0.560468233 0.769825424
## [61] 0.880773476 0.114389283 0.874113320 0.001543966 0.103946811 0.164934069
## [67] 0.709722195 0.684836609 0.428484262 0.482272052 0.164708419 0.169177458
## [73] 0.781668361 0.063360144 0.595070818 0.185573831 0.913925685 0.999385751
## [79] 0.685119727 0.685651365 0.774108550 0.757481938 0.764371548 0.631055553
## [85] 0.907349037 0.965916236 0.182615892 0.569274589 0.751739667 0.174384065
## [91] 0.983256285 0.345122163 0.900523693 0.797586347 0.809467324 0.138206114
## [97] 0.678928909 0.176733108 0.754028255 0.193661656
# Generar 100 variables normales con media 30 y desviación estándar 3.5
normal_random <- rnorm(100, mean = 30, sd = 3.5)
normal_random
## [1] 29.31360 32.91043 27.74794 28.70746 31.28120 27.89694 26.53118 30.46319
## [9] 28.88180 22.48594 30.76628 32.72652 33.89212 28.09016 30.35969 30.94884
## [17] 29.13225 36.65863 22.61792 27.78485 32.32609 28.97714 33.15995 28.26068
## [25] 35.53802 30.95334 23.17087 30.65676 23.86196 21.15534 35.75669 36.64585
## [33] 31.88663 34.70479 26.90411 27.33254 27.14643 29.74904 30.76724 30.21785
## [41] 29.64660 27.47832 27.88910 31.82048 29.57599 33.81248 29.46500 34.18874
## [49] 31.19467 27.83528 27.16252 28.04034 30.13403 24.62573 24.68723 27.15999
## [57] 30.43827 29.65149 33.65908 30.24081 28.92222 32.09934 27.99381 29.18711
## [65] 24.69951 29.76264 30.55710 26.57596 28.31258 29.71476 33.96665 27.45887
## [73] 32.42329 34.39151 29.96138 30.53832 33.47457 23.92455 29.99063 29.57407
## [81] 33.00419 35.89722 35.92128 30.96269 28.44886 34.08193 22.56761 26.66075
## [89] 30.14265 28.31661 33.11360 26.64722 32.28974 31.37165 34.89871 24.88894
## [97] 29.90651 32.87617 28.73235 31.49575
hist(normal_random,col=7,main="Grafico de la normal ")
numexp <- rexp(100,1/3)
round(numexp,1)
## [1] 10.1 1.6 0.1 0.3 5.8 0.0 3.9 4.2 1.1 0.7 0.9 1.1 3.5 1.2 1.6
## [16] 1.1 2.2 10.0 3.6 3.1 2.6 2.0 0.2 3.9 5.5 1.4 0.4 2.2 6.1 2.4
## [31] 0.7 1.6 0.6 4.2 5.4 0.5 1.6 4.6 0.4 1.1 2.0 1.1 1.0 1.8 1.3
## [46] 0.4 5.1 2.3 7.7 0.0 2.8 14.4 0.8 1.0 0.2 0.1 5.2 9.2 7.7 2.7
## [61] 0.0 1.0 3.9 0.7 0.6 1.7 2.0 0.4 0.0 0.8 8.2 5.5 1.9 4.9 0.5
## [76] 2.2 4.6 0.5 3.4 2.8 4.2 1.8 2.4 0.7 2.2 0.4 4.1 0.5 3.4 1.8
## [91] 8.2 3.6 5.3 1.1 1.7 7.9 8.7 5.8 2.6 0.9
binonm_random <- rbinom(100,12,0.25)
binonm_random
## [1] 2 2 3 4 2 1 1 2 4 2 3 2 1 2 5 2 5 3 4 3 3 3 2 3 3 0 4 4 4 1 1 3 1 3 1 1 3
## [38] 0 1 0 3 0 4 1 4 3 4 3 1 3 3 2 0 3 1 5 3 5 3 3 4 4 0 4 1 1 2 5 2 2 3 0 5 4
## [75] 4 3 2 0 2 3 6 4 4 2 2 6 3 3 2 3 5 3 6 4 3 3 4 3 2 2
evento_pois <- rpois(100,5)
tablapois <- table(evento_pois)
tablapois
## evento_pois
## 1 2 3 4 5 6 7 8 9 10 11
## 2 7 12 19 23 13 11 4 5 2 2