-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
545 lines (448 loc) · 21.6 KB
/
app.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(shinydashboard)
library(shinythemes)
library(shinyWidgets)
library(latex2exp)
library(rmarkdown)
library(Pareto)
library(evd)
library(ggplot2)
# Define UI for application that draws a histogram
ui <- dashboardPage(
skin = "green",
# Application title
dashboardHeader(title = "Probabilidad"),
dashboardSidebar(
sidebarMenu(
menuItem("Presentacion", tabName = "presentacion", icon = icon("th")),
menuItem("Section 1", tabName = "p1", icon=icon("book"),
menuItem("Distribuciones Discretas", tabName = "u1",
menuSubItem("Binomial", tabName = "dbinom"),
menuSubItem("Geometrica", tabName = "dgeom"),
menuSubItem("Binomial Negativa", tabName = "dbinomN")
),
menuItem("Distribuciones Continuas", tabName = "u2",
menuSubItem("Distribucion de Pareto", tabName = "dparet"),
menuSubItem("Distribucion de Frechet", tabName = "dfrech"),
menuSubItem("Distribución Gamma", tabName = "dgama"))),
menuItem("Section 2", tabName = "p2", icon=icon("book"),
menuItem("Esperanza y Varianza", tabName = "esperanza",
menuSubItem("Variables Continuas", tabName = "vADiscEsp"),
menuSubItem("Variables Discretas", tabName = "vAContEsp")),
menuItem("Funcion generadora", tabName = "fgenerad",
menuSubItem("Binomial", tabName = "binomFge"),
menuSubItem("Geometrica", tabName = "geomFge"),
menuSubItem("Pareto", tabName = "paretFg"))
)
)),
body <- dashboardBody(
tabItems(
tabItem(tabName = "presentacion",
#------------------------PRESENTACIÃÂN-----------------------------------
HTML('<br><br><center><img style = width:150px src="LogoITT.png"></center><br>'),
h4(strong("Instituto Tecnológico de Tlaxcala"),align = "center",tags$br(),tags$br()),
h1(strong("Probabilidad"),align = "center", style = "font-size:40px"),
h4(strong("Edgar Montiel"),align = "center",tags$br(),tags$br(),tags$br())
#-----------------------------------------------------------------------
),
tabItem(tabName = "dbinom",
h2("Distribución Binomial"),
p("La distribución binomial es una distribución de probabilidad discreta que cuenta el
número de éxitos en una secuenca de n ensayos independientes entre sà con una probabilidad
fija p de ocurrencia de éxito entre los ensayos."),
fluidRow(
box(title = "Entradas", status = "warning", solidHeader = TRUE,
sliderInput("p10",
"Probabilidad fija p:",
min = 0,
max = 1,
value = 0.5),
sliderInput("n10",
"Numero de intentos n:",
min = 1,
max = 40,
step = 1,
value = 10)
),
box(
title = "Salidas",status = "primary", solidHeader = TRUE,
plotOutput("distPlot005")
)
)
),
tabItem(tabName = "dgeom",
h2("Distribución Geométrica"),
p("Tambien conocida como distribución de Pascal, la distribución geométrica es un modelo adecuacuado
para los procesos en los que se repiten pruebas hasta la consecución del éxito a resultado deseado.
El proceso consta de un número no definido de pruebas o experimentos separados y dicho proceso
fianlizará cuando se obtenga por primera vez el resultado deseado", align = "justify"),
fluidRow(
box(title = "Entradas", status = "warning", solidHeader = TRUE,
sliderInput("p",
"Valor de la probabilidad p:",
min = 0,
max = 1,
value = 0.5),
sliderInput("n",
"Número de intentos n:",
min = 1,
max = 40,
step = 1,
value = 10)
),
box(
title = "Salidas",status = "primary", solidHeader = TRUE,
plotOutput("distPlot001")
)
)
),
#Distribucion binomial negativa
tabItem(tabName = "dbinomN", solidHeader = TRUE,
h2("Distribución Binomial Negativa"),
p("La Distribución Binomial Negativa es una distribución de probabilidad discreta
que incluye a la distribución de Pascal. Es una ampliación de las distribuciones
geométricas, utilizada en procesos en los cuales se ve necesaria la repetición de
ensayos hasta conseguir un número de casos favorables (primer éxito).",align = "justify"),
fluidRow(
box(title = "Entradas", status = "warning", solidHeader = TRUE,
sliderInput("p1",
"Valor de la probabilidad p:",
min = 0,
max = 1,
value = 0.5),
sliderInput("n1",
"Número de intentos n:",
min = 1,
max = 40,
step = 1,
value = 10)
),
box(
title = "Salidas",status = "primary", solidHeader = TRUE,
plotOutput("distPlot002")
)
)
),
tabItem(tabName = "dgama",
h2("Distribucion Gamma"),
p("la distribución gamma es una distribución con dos parámetros que pertenece a
las distribuciones de probabilidad continuas."),
fluidRow(
box(title = "Entradas", status = "warning", solidHeader = TRUE,
sliderInput("p11",
"Valor del parámetro K:",
min = 0,
max = 20,
value = 10),
sliderInput("n11",
"Valor del parámetro teta:",
min = 0,
max = 10,
step = .5,
value = 1)
),
box(
title = "Salidas",status = "primary", solidHeader = TRUE,
plotOutput("distPlot006")
)
)
),
#Distribucion de pareto
tabItem(tabName = "dparet", solidHeader = FALSE,
h2("Distribución de Pareto"),
p("Esta distribución surgió a finales del siglo XIX (Pareto, 1897) ante la preocupación
de los economistas matemáticos de proporcionar modelos probabilÃsticos que ajusten
correctamente la distribución de frecuencias de la renta personal.",align = "justify"),
fluidRow(
box(title = "Entradas", status = "warning", solidHeader = TRUE,
sliderInput("p3",
"X:",
min = 0,
max = 50,
value = 15),
sliderInput("n3",
"T:",
min = 1,
max = 100,
step = .5,
value = 3.5),
sliderInput("a",
"alpha:",
min = 1,
max = 100,
step = 1,
value = 10)
),
box(
title = "Salidas",status = "primary", solidHeader = TRUE,
plotOutput("distPlot003")
)
),
),
#Distribucion de Frechet
tabItem(tabName = "dfrech", status = "warning", solidHeader = TRUE,
h2("Distribución de Fréchet"),
p("La distribución de Fréchet es un caso especial de la distribución de valores extremos generalizada.
En la hidrologÃa, se utiliza la distribución de Fréchet para analizar variables aleatorias como valores máximos de la precipitación y la descarga de rÃos,
y además para describir épocas de sequÃa."),
fluidRow(
box(title = "Entradas", status = "warning", solidHeader = TRUE,
sliderInput("p4",
"Valor de x mÃnimo:",
min = 0,
max = 40,
value = 1),
sliderInput("pmax",
"Valor de x máximo:",
min = 0,
max = 40,
value = 1
),
sliderInput("n4",
"Parámetro de localización m:",
min = 1,
max = 40,
step = 1,
value = 1),
sliderInput("p5",
"Escala s>0:",
min = 0,
max = 1,
step = .1,
value = .1),
sliderInput("n5",
"Valor de forma alpha>0:",
min = 0,
max = 1,
step = .1,
value = .1)
),
box(
title = "Salidas",status = "primary", solidHeader = TRUE,
plotOutput("distPlot004")
)
)
),
tabItem(tabName = "vADiscEsp",
h2("Esperanza y Varianza de variables aleatorias continuas"),
fluidRow(
box(title = "Entradas", status = "warning", solidHeader = TRUE,
textInput("funcn", "Ingresa tu funcion de probabilidad ", "x^2"),
textInput("inferior", "Ingresa el indice inferior", "0"),
textInput("superior", "Ingresa el indice superior", "1")
),
box(
title = "Esperanza",status = "primary", solidHeader = TRUE,
HTML("<strong>Resultado:</strong>"),
tags$div(style= "text-aling: center", textOutput("esperanza2"))
),
),
fluidRow(
box(title = "Entradas", status = "warning", solidHeader = TRUE,
textInput("funcn2", "Ingresa tu funcion de probabilidad ", "(1 - .33)^2 * 2*x"),
textInput("inferior", "Ingresa el indice inferior", "0"),
textInput("superior", "Ingresa el indice superior", "1")
),
box(
title = "Varianza",status = "primary", solidHeader = TRUE,
HTML("<strong>Resultado:</strong>"),
tags$div(style= "text-aling: center", textOutput("varianza2"))
)
)
),
tabItem(tabName = "vAContEsp",
h2("Esperanza y Varianza de variables aleatorias discretas"),
fluidRow(
box(
title = "Entradas" , status = "warning", solidHeader = TRUE,
textInput("valoresX", "Valores en x: ", "-1, 0, 1, 2"),
textInput("valoresfx", "Valores en f(x): ", ".125, .5, .125, .250")
),
box(
title = "Esperanza",status = "primary", solidHeader = TRUE,
HTML("<strong>Resultado:</strong>"),
tags$div(style= "text-aling: center", textOutput("esperanz"))
),
box(
title = "Varianza",status = "primary", solidHeader = TRUE,
HTML("<strong>Resultado:</strong>"),
tags$div(style= "text-aling: center", textOutput("varianza"))
),
),
), #fin tabItem vaContEsp
tabItem(tabName = "binomFge",
h2("Funcion generadora"),
fluidRow(
box(
title = "Entrada", status = "warning", solidHeader = TRUE,
sliderInput("fg",
"Tamaño entre cada valor:",
min = 0,
max = 500,
step = 50,
value = 200)
), box(
title = "Salidas",status = "primary", solidHeader = TRUE,
plotOutput("fgeneradora")
)
)),
tabItem(tabName = "geomFge",
h2("Funcion generadora"),
fluidRow(
box(
title = "Entrada", status = "warning", solidHeader = TRUE,
sliderInput("fg2",
"Tamaño entre cada valor:",
min = 0,
max = 500,
step = 50,
value = 50)
), box(
title = "Salidas",status = "primary", solidHeader = TRUE,
plotOutput("fgeneradora2")
)
)),
tabItem(tabName = "paretFg",
h2("Funcion generadora"),
fluidRow(
box(
title = "Entrada", status = "warning", solidHeader = TRUE,
sliderInput("fg3",
"Tamaño entre cada valor:",
min = 0,
max = 500,
step = 50,
value = 50)
), box(
title = "Salidas",status = "primary", solidHeader = TRUE,
plotOutput("fgeneradora3")
)
))
) #fin tabItems
)#Fin DashboardBody
) #Fin DashBoard
# Define server logic required to draw a histogram
service <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$n + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
output$distPlot001 <- renderPlot({
x <- 0:input$n
probs <- dgeom(x, prob = input$p)
qplot(x, probs, geom = c("point", "line"),
main = paste("Densidad de distribución Geometrica, n = ", as.character(input$n)),
ylab = "p(x)", ylim = c(0, 1))
})
output$distPlot002 <- renderPlot({
x <- 0:input$n1
probs <- dnbinom(x, size = input$n1, prob = input$p1)
qplot(x, probs, geom = c("point", "line"),
main = paste("Densidad de distribución Binomial Negativa, n = ", as.character(input$n)),
ylab = "p(x)", ylim = c(0, 1))
})
output$distPlot003 <- renderPlot({
x <- 0:input$p3
probs <- dPareto(x, input$n3, input$a)
qplot(x, probs, geom = c("point", "line"),
main = paste("Densidad de distribución de Pareto, n = ", as.character(input$n)),
ylab = "p(x)", ylim = c(1,0))
})
output$distPlot004 <- renderPlot({
x <- input$p4:input$pmax
probs <- dfrechet(x, input$n4, input$p5, input$n5)
qplot(x, probs, geom = c("point", "line"),
main = paste("Densidad de distribución de Fréchet"),
ylab = "p(x)", ylim = c(1,0))
})
output$distPlot005 <- renderPlot({
x <- 0:input$n10
probs <- dbinom(x, size = input$n10, prob = input$p10)
qplot(x, probs, geom = c("point", "line"),
main = paste("Densidad de distribució binomial, n = ", as.character(input$n10)),
ylab = "p(x)", ylim = c(0, 1)) + theme_bw()
})
output$distPlot006 <- renderPlot({
x <- 0:20
alph <- 1 / input$n11
probs <- dgamma(x, input$p11, alph)
qplot(x, probs, geom = c("point", "line"),
main = paste("Densidad de distribución gamma, n = ", as.character(input$n11)),
ylab = "p(x)", ylim = c(0, 1)) + theme_bw()
})
output$esperanz <- renderText({
x <- as.numeric(unlist(strsplit(input$valoresX,",")))
fx <- as.numeric(unlist(strsplit(input$valoresfx,",")))
suma <- 0.00 #
for (i in 1: length (x)){
suma <- suma + x[i]* fx[i]
}
paste(suma)
})
output$varianza <- renderText({
x <- as.numeric(unlist(strsplit(input$valoresX,",")))
fx <- as.numeric(unlist(strsplit(input$valoresfx,",")))
med <- 0.00
for (i in 1: length(x)){ #Rcorremos el tamaño el la lista
med <- med + x[i]* fx[i] # en cada iteracion se realiza la operación correspondiente al indice y se suma al contador
}
var <- 0.00 #Iniciamos una variable que almacenará la varianza
for (j in 1: length(x)){ #iteramos sobre el tamaño de la lista nuevamente
var <- var + (x[i]*med)^2 * fx[i] #sumamos el valor de la operacion de cada iteracion, se usa la media
}
paste(var) #mandamos el valor de var
})
output$esperanza2 <- renderPrint({
body <- input$funcn
eval(parse(text = paste('f <- function(x) { return(' , body , ')}', sep='')))
integrate(f, lower = 0, upper = 1)
})
output$varianza2 <- renderPrint({
body <- input$funcn2
funcion <- eval(parse(text = paste('f <- function(x) { return(' , body , ')}', sep='')))
integrate(f, lower = 0, upper = 1)
})
output$fgeneradora <- renderPlot({
Lista <- c()
for (i in seq(50, 50000, by=input$fg)) {
x <- i
datos <- c(rbinom(x, 50000, 0.1))
media = median(datos)
Lista <- c(Lista, media)
}
plot(Lista, type = "l", main = "Función generadora de momentos")
})
output$fgeneradora2 <- renderPlot({
Lista <- c()
for (i in seq(50, 10000, by=input$fg2)) {
x <- i
datos <- c(rgeom(x, 0.1))
media = median(datos)
Lista <- c(Lista, media)
}
plot(Lista, type = "l", main = "Función generadora de momentos")
})
output$fgeneradora3 <- renderPlot({
Lista <- c()
for (i in seq(50, 10000, by=input$fg3)) {
x <- i
datos <- c(rPareto(x,10000, 0.1))
media = median(datos)
Lista <- c(Lista, media)
}
plot(Lista, type = "l", main = "Función generadora de momentos")
})
}
# Run the application
shinyApp(ui = ui, server = service)