Spaces:
Running
Running
Upload 2 files
Browse files
server.R
CHANGED
@@ -1,23 +1,55 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
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 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
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 ε:"),
|
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 σ:"),
|
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 ε:"),
|
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 |
+
)))
|