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
+
# ----------------------- Shadow function ----------------------
|
6 |
+
shadowtext <- function(x, y=NULL, labels, col='white', bg='black',
|
7 |
+
theta= seq(0, 2*pi, length.out=50), r=0.1, ... ) {
|
8 |
+
|
9 |
+
xy <- xy.coords(x,y)
|
10 |
+
xo <- r*strwidth('A')
|
11 |
+
yo <- r*strheight('A')
|
12 |
+
|
13 |
+
# draw background text with small shift in x and y in background colour
|
14 |
+
for (i in theta) {
|
15 |
+
text( xy$x + cos(i)*xo, xy$y + sin(i)*yo, labels, col=bg, ... )
|
16 |
+
}
|
17 |
+
# draw actual text in exact xy position in foreground colour
|
18 |
+
text(xy$x, xy$y, labels, col=col, ... )
|
19 |
+
}
|
20 |
+
#--------------------------------------------------------------
|
21 |
+
|
22 |
+
output$miplot <- renderPlot({
|
23 |
+
|
24 |
+
#----------------------------- Normal ---------------------------------
|
25 |
+
|
26 |
+
if(input$Distribucion == "Normal"){
|
27 |
+
if(input$Propede == "Percentil"){
|
28 |
+
|
29 |
+
media <- input$Media
|
30 |
+
desvi <- input$Sd
|
31 |
+
proba <- input$Probabilidad
|
32 |
+
percentil <- qnorm(p=proba, mean=media, sd=desvi)
|
33 |
+
|
34 |
+
k <- 5 # numero de desviaciones
|
35 |
+
curve(dnorm(x, media, desvi), xlim=media+c(-k,k)*desvi, lwd=3,
|
36 |
+
main='Distribución normal', ylab="", xlab="", axes=FALSE)
|
37 |
+
axis(1, at=seq(media-k*desvi, media+k*desvi, desvi), pos=0)
|
38 |
+
axis(2, las=1)
|
39 |
+
secuencia <- seq(media-k*desvi, percentil, length.out=10000)
|
40 |
+
cord.x <- c(media-k*desvi, secuencia, percentil)
|
41 |
+
cord.y <- c(0, dnorm(secuencia, media, desvi), 0)
|
42 |
+
polygon(cord.x, cord.y, col='steelblue')
|
43 |
+
shadowtext(x=percentil, y=0, round(percentil, 2), col="chartreuse", cex=2)
|
44 |
+
title(sub=bquote(P(X<.(percentil))==.(proba)), cex.sub=2)
|
45 |
+
|
46 |
+
}
|
47 |
+
|
48 |
+
else {
|
49 |
+
media <- input$Media
|
50 |
+
desvi <- input$Sd
|
51 |
+
percentil <- input$Percentil
|
52 |
+
proba <- pnorm(percentil, media, desvi)
|
53 |
+
|
54 |
+
k <- 5 # numero de desviaciones
|
55 |
+
curve(dnorm(x, media, desvi), xlim=media+c(-k,k)*desvi, lwd=3,
|
56 |
+
main='Distribución normal', ylab="", xlab="", axes=FALSE)
|
57 |
+
axis(1, at=seq(media-k*desvi, media+k*desvi, desvi), pos=0)
|
58 |
+
axis(2, las=1)
|
59 |
+
if (percentil > media-k*desvi) {
|
60 |
+
secuencia <- seq(media-k*desvi, percentil, length.out=10000)
|
61 |
+
cord.x <- c(media-k*desvi, secuencia, percentil)
|
62 |
+
cord.y <- c(0, dnorm(secuencia, media, desvi), 0)
|
63 |
+
polygon(cord.x, cord.y, col='steelblue')
|
64 |
+
altura <- dnorm(percentil, media, desvi)
|
65 |
+
shadowtext(x=percentil, y=altura/2, round(proba, 2),
|
66 |
+
col="orchid2", cex=2)
|
67 |
+
}
|
68 |
+
title(sub=bquote(P(X<.(percentil))==.(proba)), cex.sub=2)
|
69 |
+
|
70 |
+
}}
|
71 |
+
|
72 |
+
#----------------------------- t-student ---------------------------------
|
73 |
+
|
74 |
+
if(input$Distribucion == "t-student"){
|
75 |
+
|
76 |
+
|
77 |
+
if(input$Propede == "Percentil"){
|
78 |
+
df=input$grados
|
79 |
+
proba <- input$Probabilidad
|
80 |
+
percentil <- qt(p=proba, df=df, lower.tail=F)
|
81 |
+
|
82 |
+
curve(dt(x, df), xlim=c(-5,5), lwd=3,
|
83 |
+
main='Distribución t-student', ylab="", xlab="",
|
84 |
+
axes=FALSE)
|
85 |
+
axis(1, at=seq(-5, 5, by=0.5), pos=0)
|
86 |
+
axis(2, las=1)
|
87 |
+
secuencia <- seq(percentil, 5, length.out=10000)
|
88 |
+
cord.x <- c(percentil, secuencia, 5)
|
89 |
+
cord.y <- c(0, dt(secuencia, df=df), 0)
|
90 |
+
polygon(cord.x, cord.y, col='darkolivegreen3')
|
91 |
+
shadowtext(x=percentil, y=0.01, round(percentil, 2),
|
92 |
+
col="chartreuse", cex=2)
|
93 |
+
title(sub=bquote(P(t>.(percentil))==.(proba)), cex.sub=2)
|
94 |
+
|
95 |
+
output$perce <- renderText(percentil)
|
96 |
+
}
|
97 |
+
|
98 |
+
else {
|
99 |
+
df=input$grados
|
100 |
+
percentil=input$Percentil
|
101 |
+
proba <- pt(q=percentil, df=df, lower.tail=F)
|
102 |
+
|
103 |
+
curve(dt(x, df), xlim=c(-5,5), lwd=3,
|
104 |
+
main='Distribución t-student', ylab="", xlab="",
|
105 |
+
axes=FALSE)
|
106 |
+
axis(1, at=seq(-5, 5, by=0.5), pos=0)
|
107 |
+
axis(2, las=1)
|
108 |
+
secuencia <- seq(percentil, 5, length.out=10000)
|
109 |
+
cord.x <- c(percentil, secuencia, 5)
|
110 |
+
cord.y <- c(0, dt(secuencia, df=df), 0)
|
111 |
+
polygon(cord.x, cord.y, col='darkolivegreen3')
|
112 |
+
altura <- dt(x=percentil, df=df)
|
113 |
+
shadowtext(x=percentil, y=altura/2, round(proba, 2),
|
114 |
+
col="orchid2", cex=2)
|
115 |
+
title(sub=bquote(P(t>.(percentil))==.(proba)), cex.sub=2)
|
116 |
+
|
117 |
+
}
|
118 |
+
|
119 |
+
}
|
120 |
+
|
121 |
+
#----------------------------- F ---------------------------------
|
122 |
+
|
123 |
+
if(input$Distribucion == "F"){
|
124 |
+
|
125 |
+
|
126 |
+
if(input$Propede == "Percentil"){
|
127 |
+
|
128 |
+
proba <- input$Probabilidad
|
129 |
+
df1=input$grados1
|
130 |
+
df2=input$grados2
|
131 |
+
percentil <- qf(p=proba, df1, df2, lower.tail=F)
|
132 |
+
|
133 |
+
max.x <- 3 * percentil
|
134 |
+
curve(df(x, df1, df2), xlim=c(0, max.x), lwd=3,
|
135 |
+
main='Distribución F', ylab="", xlab="", axes=FALSE)
|
136 |
+
axis(1, at=seq(0, max.x, by=0.5), pos=0)
|
137 |
+
axis(2, las=1)
|
138 |
+
secuencia <- seq(percentil, max.x, length.out=10000)
|
139 |
+
cord.x <- c(percentil, secuencia, max.x)
|
140 |
+
cord.y <- c(0, df(secuencia, df1, df2), 0)
|
141 |
+
polygon(cord.x, cord.y, col='lightsalmon3')
|
142 |
+
shadowtext(x=percentil, y=0.01, round(percentil, 2),
|
143 |
+
col="chartreuse", cex=2)
|
144 |
+
title(sub=bquote(P(F>.(percentil))==.(proba)), cex.sub=2)
|
145 |
+
|
146 |
+
}
|
147 |
+
|
148 |
+
else {
|
149 |
+
df1=input$grados1
|
150 |
+
df2=input$grados2
|
151 |
+
percentil=input$Percentil
|
152 |
+
proba <- pf(q=percentil, df1, df2, lower.tail=F)
|
153 |
+
|
154 |
+
max.x <- 3 * percentil
|
155 |
+
curve(df(x, df1, df2), xlim=c(0, max.x), lwd=3,
|
156 |
+
main='Distribución F', ylab="", xlab="", axes=FALSE)
|
157 |
+
axis(1, at=seq(0, max.x, by=0.5), pos=0)
|
158 |
+
axis(2, las=1)
|
159 |
+
secuencia <- seq(percentil, max.x, length.out=10000)
|
160 |
+
cord.x <- c(percentil, secuencia, max.x)
|
161 |
+
cord.y <- c(0, df(secuencia, df1, df2), 0)
|
162 |
+
polygon(cord.x, cord.y, col='lightsalmon3')
|
163 |
+
altura <- df(x=percentil, df1, df2)
|
164 |
+
shadowtext(x=percentil, y=altura/2, round(proba, 2),
|
165 |
+
col="orchid2", cex=2)
|
166 |
+
title(sub=bquote(P(F>.(percentil))==.(proba)), cex.sub=2)
|
167 |
+
|
168 |
+
|
169 |
+
}}
|
170 |
+
|
171 |
+
#----------------------------- chi ---------------------------------
|
172 |
+
|
173 |
+
if(input$Distribucion == "chi.cuadrada"){
|
174 |
+
|
175 |
+
|
176 |
+
if(input$Propede == "Percentil"){
|
177 |
+
proba <- input$Probabilidad
|
178 |
+
df=input$Grados
|
179 |
+
percentil <- qchisq(p=proba, df, lower.tail=F)
|
180 |
+
|
181 |
+
max.x <- qchisq(p=0.99, df)
|
182 |
+
curve(dchisq(x, df), xlim=c(0, max.x), lwd=3,
|
183 |
+
main=expression('Distribución' ~ chi^2), ylab="", xlab="", axes=FALSE)
|
184 |
+
axis(1, at=seq(0, max.x, by=0.5), pos=0)
|
185 |
+
axis(2, las=1)
|
186 |
+
secuencia <- seq(percentil, max.x, length.out=10000)
|
187 |
+
cord.x <- c(percentil, secuencia, max.x)
|
188 |
+
cord.y <- c(0, dchisq(secuencia, df), 0)
|
189 |
+
polygon(cord.x, cord.y, col='yellow3')
|
190 |
+
shadowtext(x=percentil, y=0, round(percentil, 2),
|
191 |
+
col="chartreuse", cex=2)
|
192 |
+
title(sub=bquote(P(chi^2>.(percentil))==.(proba)), cex.sub=2)
|
193 |
+
|
194 |
+
|
195 |
+
}
|
196 |
+
else {
|
197 |
+
|
198 |
+
df=input$Grados
|
199 |
+
percentil=input$Percentil
|
200 |
+
proba <- pchisq(q=percentil, df, lower.tail=F)
|
201 |
+
|
202 |
+
max.x <- qchisq(p=0.99, df)
|
203 |
+
curve(dchisq(x, df), xlim=c(0, max.x), lwd=3,
|
204 |
+
main=expression('Distribución' ~ chi^2), ylab="", xlab="", axes=FALSE)
|
205 |
+
axis(1, at=seq(0, max.x, by=0.5), pos=0)
|
206 |
+
axis(2, las=1)
|
207 |
+
secuencia <- seq(percentil, max.x, length.out=10000)
|
208 |
+
cord.x <- c(percentil, secuencia, max.x)
|
209 |
+
cord.y <- c(0, dchisq(secuencia, df), 0)
|
210 |
+
polygon(cord.x, cord.y, col='yellow3')
|
211 |
+
altura <- dchisq(x=percentil, df)
|
212 |
+
shadowtext(x=percentil, y=altura/2, round(proba, 2),
|
213 |
+
col="orchid2", cex=2)
|
214 |
+
title(sub=bquote(P(chi^2>.(percentil))==.(proba)), cex.sub=2)
|
215 |
+
|
216 |
+
|
217 |
+
}}
|
218 |
+
})
|
219 |
+
})
|
ui.R
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
shinyUI(fluidPage(
|
2 |
+
titlePanel("Distribuciones muestrales"),
|
3 |
+
h4(p("Esta aplicación te ayudará a calcular probabilidades y
|
4 |
+
percentiles de distribuciones asociadas al muestreo."),
|
5 |
+
align="left"),
|
6 |
+
sidebarLayout(
|
7 |
+
sidebarPanel(
|
8 |
+
selectInput(inputId="Distribucion",
|
9 |
+
label="Elija la distribución:",
|
10 |
+
choices=c("Normal", "t-student", "chi.cuadrada", "F"),
|
11 |
+
selected="Normal"),
|
12 |
+
|
13 |
+
|
14 |
+
conditionalPanel(condition="input.Distribucion=='Normal'",
|
15 |
+
numericInput(inputId="Media",
|
16 |
+
label=HTML("Ingrese la media μ:"),
|
17 |
+
value="0",
|
18 |
+
step=0.1),
|
19 |
+
|
20 |
+
numericInput(inputId="Sd",
|
21 |
+
label=HTML("Ingrese la desviacion σ:"),
|
22 |
+
min=0.1,
|
23 |
+
value="1",
|
24 |
+
step=0.1) ),
|
25 |
+
|
26 |
+
conditionalPanel(condition="input.Distribucion=='t-student'",
|
27 |
+
numericInput(inputId="grados",
|
28 |
+
label="Ingrese grados de libertad",
|
29 |
+
min=0.1,
|
30 |
+
step=0.1,
|
31 |
+
value="1")),
|
32 |
+
|
33 |
+
|
34 |
+
conditionalPanel(condition="input.Distribucion=='F'",
|
35 |
+
numericInput(inputId="grados1",
|
36 |
+
label="Ingrese los grados de libertad del numerador",
|
37 |
+
value="10"),
|
38 |
+
|
39 |
+
numericInput(inputId="grados2",
|
40 |
+
label="Ingrese los grados de libertad del denominador",
|
41 |
+
value="20")),
|
42 |
+
|
43 |
+
conditionalPanel(condition="input.Distribucion=='chi.cuadrada'",
|
44 |
+
numericInput(inputId="Grados",
|
45 |
+
label="Ingrese los grados de libertad",
|
46 |
+
value="3")),
|
47 |
+
|
48 |
+
selectInput(inputId="Propede",
|
49 |
+
label="Opciones para calcular:",
|
50 |
+
choices=c("Probabilidad","Percentil"),
|
51 |
+
selected="Percentil"),
|
52 |
+
|
53 |
+
conditionalPanel(condition="input.Propede=='Probabilidad'",
|
54 |
+
numericInput(inputId="Percentil",
|
55 |
+
label="Ingrese percentil",
|
56 |
+
value=1, step=0.01)),
|
57 |
+
|
58 |
+
conditionalPanel(condition="input.Propede=='Percentil'",
|
59 |
+
numericInput(inputId="Probabilidad",
|
60 |
+
label="Ingrese probabilidad",
|
61 |
+
value=0.70, step=0.001,
|
62 |
+
min=0.001, max=0.999)),
|
63 |
+
img(src="logo.png", height = 56, width = 140),
|
64 |
+
img(src="udea.png", height = 65, width = 60),
|
65 |
+
br(),
|
66 |
+
p("App creada por el Semillero de R de la Universidad Nacional de Colombia:"),
|
67 |
+
tags$a(href="https://srunal.github.io", "https://srunal.github.io")
|
68 |
+
|
69 |
+
),
|
70 |
+
|
71 |
+
|
72 |
+
mainPanel(
|
73 |
+
tabsetPanel(type = "tabs",
|
74 |
+
tabPanel("Gráfica", plotOutput(outputId="miplot"))
|
75 |
+
|
76 |
+
|
77 |
+
)
|
78 |
+
)
|
79 |
+
)))
|