FreddyHernandez commited on
Commit
ccf2fef
verified
1 Parent(s): 11127d7

Upload 2 files

Browse files
Files changed (2) hide show
  1. server.R +55 -23
  2. ui.R +81 -16
server.R CHANGED
@@ -1,23 +1,55 @@
1
- function(input, output, session) {
2
-
3
- # Combine the selected variables into a new data frame
4
- selectedData <- reactive({
5
- iris[, c(input$xcol, input$ycol)]
6
- })
7
-
8
- clusters <- reactive({
9
- kmeans(selectedData(), input$clusters)
10
- })
11
-
12
- output$plot1 <- renderPlot({
13
- palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
14
- "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))
15
-
16
- par(mar = c(5.1, 4.1, 0, 1))
17
- plot(selectedData(),
18
- col = clusters()$cluster,
19
- pch = 20, cex = 3)
20
- points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
21
- })
22
-
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ library(shiny)
2
+
3
+ shinyServer(function(input, output, session){
4
+
5
+ output$grafica <- renderPlot({
6
+
7
+ if(input$tipo == "Proporcion"){
8
+ N <- input$Nprop
9
+ if (is.null(N)) N <- 500000000
10
+ e <- input$eprop
11
+ p <- input$p
12
+ nc <- seq(from=0.90, to=0.99, by=0.01)
13
+ z <- qnorm((1-nc)/2, lower.tail=F)
14
+ if (input$Ncp=='No') n <- z^2 * p * (1-p) / e^2
15
+ if (input$Ncp=='Si') n <- N * z^2 * p * (1-p) / ((N-1) * e^2 + z^2 * p * (1-p))
16
+ n <- ceiling(n)
17
+ nc <- 100 * nc
18
+ plot(x=nc, y=n, axes=F,
19
+ cex=2, pch=19, col='deepskyblue3',
20
+ xlab='Nivel de confianza (NC)',
21
+ ylab='Tama帽o de muestra',
22
+ main=expression(Tama帽o~de~muestra~para~estimar~P))
23
+ Axis(side=1, at=nc)
24
+ Axis(side=2, at=n, las=1)
25
+ segments(x0=nc, y0=min(n), x1=nc, y1=n, lty='dotted', col=gray(0.5))
26
+ segments(x0=min(nc), y0=n, x1=nc, y1=n, lty='dotted', col=gray(0.5))
27
+
28
+ }
29
+
30
+ if(input$tipo == "Media"){
31
+ N <- input$Nmean
32
+ e <- input$emean
33
+ sigma <- input$sigma
34
+ nc <- seq(from=0.90, to=0.99, by=0.01)
35
+ z <- qnorm((1-nc)/2, lower.tail=F)
36
+ if (input$Ncm=='No') n <- z^2 * sigma^2 / e^2
37
+ if (input$Ncm=='Si') n <- N * z^2 * sigma^2 / ((N-1) * e^2 + z^2 * sigma^2)
38
+ n <- ceiling(n)
39
+ nc <- 100 * nc
40
+ plot(x=nc, y=n, axes=F,
41
+ cex=2, pch=19, col='deepskyblue3',
42
+ xlab='Nivel de confianza (NC)',
43
+ ylab='Tama帽o de muestra',
44
+ main=expression(Tama帽o~de~muestra~para~estimar~mu))
45
+ Axis(side=1, at=nc)
46
+ Axis(side=2, at=n, las=1)
47
+ segments(x0=nc, y0=min(n), x1=nc, y1=n, lty='dotted', col=gray(0.5))
48
+ segments(x0=min(nc), y0=n, x1=nc, y1=n, lty='dotted', col=gray(0.5))
49
+
50
+ }
51
+
52
+ })
53
+
54
+
55
+ })
ui.R CHANGED
@@ -1,16 +1,81 @@
1
- # k-means only works with numerical variables,
2
- # so don't give the user the option to select
3
- # a categorical variable
4
- vars <- setdiff(names(iris), "Species")
5
-
6
- pageWithSidebar(
7
- headerPanel('Iris k-means clustering'),
8
- sidebarPanel(
9
- selectInput('xcol', 'X Variable', vars),
10
- selectInput('ycol', 'Y Variable', vars, selected = vars[[2]]),
11
- numericInput('clusters', 'Cluster count', 3, min = 1, max = 9)
12
- ),
13
- mainPanel(
14
- plotOutput('plot1')
15
- )
16
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ shinyUI(fluidPage(
2
+ titlePanel("Tama帽os de muestra"),
3
+ h4(p("Esta aplicaci贸n entrega los tama帽os de muestra para
4
+ diferentes niveles de confianza cuando el inter茅s es
5
+ estimar una proporci贸n o una media."), align="left"),
6
+ sidebarLayout(
7
+ sidebarPanel(
8
+ selectInput(inputId="tipo",
9
+ label="Elija el tipo de problema para el cual quiere calcular n:",
10
+ choices=c("Proporcion", "Media"),
11
+ selected="Media"),
12
+
13
+ #------- proporcion
14
+
15
+ conditionalPanel(condition="input.tipo=='Proporcion'",
16
+
17
+ selectInput(inputId="Ncp",
18
+ label="Conoce usted el tama帽o N de la poblaci贸n?",
19
+ choices=c('Si', 'No'),
20
+ selected="No"),
21
+
22
+ conditionalPanel("input.Ncp=='Si'",
23
+
24
+ numericInput(inputId="Nprop",
25
+ label="Ingrese el tama帽o de la poblaci贸n",
26
+ min=5,
27
+ value=500,
28
+ step=1) ),
29
+
30
+ sliderInput(inputId="p",
31
+ label="Ingrese una estimaci贸n preliminar para p,
32
+ caso no tenga idea use 0.5.",
33
+ min=0.01,
34
+ max=0.99,
35
+ value=0.8,
36
+ step=0.01),
37
+
38
+ sliderInput(inputId="eprop",
39
+ label=HTML("Ingrese el error admisible &epsilon;:"),
40
+ min=0.01,
41
+ max=0.99,
42
+ value=0.06,
43
+ step=0.01)),
44
+ #------- media
45
+
46
+ conditionalPanel(condition="input.tipo=='Media'",
47
+
48
+ selectInput(inputId="Ncm",
49
+ label="Conoce usted el tama帽o N de la poblaci贸n?",
50
+ choices=c('Si', 'No'),
51
+ selected="No"),
52
+
53
+ conditionalPanel("input.Ncm=='Si'",
54
+
55
+ numericInput(inputId="Nmean",
56
+ label="Ingrese el tama帽o de la poblaci贸n N",
57
+ min=2,
58
+ value=30,
59
+ step=1) ),
60
+
61
+ numericInput(inputId="sigma",
62
+ label=HTML("Ingrese una estimaci贸n de &sigma;:"),
63
+ min=0.01,
64
+ max=1000,
65
+ value=12,
66
+ step=0.1),
67
+
68
+ numericInput(inputId="emean",
69
+ label=HTML("Ingrese el error admisible &epsilon;:"),
70
+ min=0.01,
71
+ value=5,
72
+ step=0.1)),
73
+
74
+ p("App creada por el Semillero de R de la Universidad Nacional de Colombia."),
75
+ tags$a(href="https://srunal.github.io", "https://srunal.github.io")
76
+
77
+ ),
78
+
79
+
80
+ mainPanel( plotOutput("grafica") )
81
+ )))