Skip to content

Commit

Permalink
App
Browse files Browse the repository at this point in the history
  • Loading branch information
Dfranzani committed Nov 11, 2024
1 parent 8d9bfc4 commit f4184e2
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .Rproj.user/9A1153C7/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"activeTab": 0,
"activeTab": 1,
"activeTabSourceWindow0": 0
}
4 changes: 2 additions & 2 deletions .Rproj.user/9A1153C7/pcs/source-window.pper
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sourceWindowGeometry": {
"w82hsabbadq8f": {
"ordinal": 4,
"wlgs0n0ezrjv8": {
"ordinal": 5,
"x": 1920,
"y": 37,
"width": 1080,
Expand Down
2 changes: 1 addition & 1 deletion .Rproj.user/9A1153C7/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"left": {
"splitterpos": 439,
"splitterpos": 440,
"topwindowstate": "NORMAL",
"panelheight": 944,
"windowheight": 982
Expand Down
2 changes: 1 addition & 1 deletion .Rproj.user/9A1153C7/sources/prop/B92398CD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "5,0",
"cursorPosition": "126,74",
"scrollLine": "0"
}
6 changes: 3 additions & 3 deletions .Rproj.user/9A1153C7/sources/prop/F6A8DCF6
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source_window_id": "w82hsabbadq8f",
"source_window_id": "",
"Source": "Source",
"cursorPosition": "341,19",
"scrollLine": "297"
"cursorPosition": "0,14",
"scrollLine": "0"
}
1 change: 1 addition & 0 deletions .Rproj.user/9A1153C7/sources/prop/INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
~%2FMEGA%2FProgramaci%C3%B3n%2FTrabajos%20en%20R%2FBookdown%2FCursos%20de%20Estad%C3%ADstica%2FApp%20Shiny%20de%20cursos%2FApp%20Estadistica%20II%2FApp%2Fui.R="4C7F59B4"
~%2FMEGA%2FProgramaci%C3%B3n%2FTrabajos%20en%20R%2FBookdown%2FCursos%20de%20Estad%C3%ADstica%2FApp%20Shiny%20de%20cursos%2FApp%20Estadistica%2FApp%2Fserver.R="F6A8DCF6"
~%2FMEGA%2FProgramaci%C3%B3n%2FTrabajos%20en%20R%2FBookdown%2FCursos%20de%20Estad%C3%ADstica%2FApp%20Shiny%20de%20cursos%2FApp%20Estadistica%2FApp%2Fui.R="B92398CD"
~%2FMEGA%2FProgramaci%C3%B3n%2FTrabajos%20en%20R%2FBookdown%2FCursos%20de%20Estad%C3%ADstica%2FApp%20Shiny%20de%20cursos%2FApp%20Estadistica%2FREADME.md="7434C68C"
3 changes: 2 additions & 1 deletion .Rproj.user/shared/notebooks/paths
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/home/daniel/MEGA/Programación/Trabajos en R/Bookdown/Cursos de Estadística/App Shiny de cursos/App Estadistica II/.Rbuildignore="D9492D28"
/home/daniel/MEGA/Programación/Trabajos en R/Bookdown/Cursos de Estadística/App Shiny de cursos/App Estadistica/App/server.R="A028F835"
/home/daniel/MEGA/Programación/Trabajos en R/Bookdown/Cursos de Estadística/App Shiny de cursos/App Estadistica/README.md="A87FC22D"
95 changes: 94 additions & 1 deletion App/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ library(shiny)

function(input, output, session) {


### Distribuciones muestrales

observeEvent(input$distribucionDM1,{
Expand Down Expand Up @@ -392,6 +391,70 @@ function(input, output, session) {
})
}
})

### Pruebas de hipótesis

# Función para generar el gráfico del estadístico de prueba

# Función para generar el gráfico del IC
grafico_IC_PH = function(ic, mediaMuestra, varianza, mu0, tipoPH, nMuestra){

limites = mu0 + c(-1,1)*3*sqrt(varianza/nMuestra)

valores_x = seq(from = limites[1], to = limites[2], by = 0.01)
plot(x = valores_x, y = dnorm(x = valores_x, mean = mu0, sd = sqrt(varianza/nMuestra)),
main = "Distribución de la media", xlab = "Valores del promedio", ylab = "Densidad",
las = 1, xaxt = "n", type = "l", bty = "n")
axis(side = 1, at = round(c(limites[1], mu0, limites[2]), 3),
labels = round(c(limites[1], mu0, limites[2]), 3),
col.axis = "darkblue", cex.axis = 1.2)

}

valor_critico = function(confianza, tipo, mu0, varianza, nMuestra, mediaMuestra){
if(tipo == "two.sided") {
valor_critico = qnorm(1 - (1 - confianza)/2)
} else if(tipo == "less") {
valor_critico = qnorm(1 - confianza)
} else {
valor_critico = qnorm(confianza)
}

estadistico_prueba = (mediaMuestra - mu0)/(sqrt(varianza/nMuestra))

return(c(estadistico_prueba, valor_critico))
}


observeEvent(input$go_PH, {
confianza = input$confianzaPH/100
mu0 = input$mu0PH
mediaMuestra = input$mediaMuestraPH
tipoPH = switch(input$tipoPH, "Bilateral" = "two.sided", "Unilateral derecha" = "greater", "Unilateral izquierda" = "less")
extremos = switch(tipoPH, "two.sided" = 1:2, "less" = 2, "greater" = 1)
varianza = input$sigma2PH
nombre_media = "Una"
nMuestra = input$nPH

# Los argumentos data debe ser el promedio n veces para que calce con el cálculo del IC de la función "calculo_IC"
ic = calculo_IC(data1 = rep(mediaMuestra, nMuestra), tipo = tipoPH, varianzas_conocidas = TRUE, varianza = varianza,
extremos = extremos, confianza = confianza, media = mediaMuestra, tamanos_muestrales = nMuestra)

valor_critico = valor_critico(confianza = confianza, tipo = tipoPH, mu0 = mu0, varianza = varianza,
nMuestra = nMuestra, mediaMuestra = mediaMuestra)

output$plot_ph = renderPlot({
plot(ic[1], ic[2])
}, height = 400)

output$plot_ic_ph = renderPlot({
grafico_IC_PH(ic = ic, media = mediaMuestra, varianza = varianza, mu0 = mu0, tipoPH = tipoPH, nMuestra = nMuestra)
}, height = 400)

})


# End general function
}


Expand All @@ -402,3 +465,33 @@ function(input, output, session) {

































36 changes: 28 additions & 8 deletions App/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ panelLateral = dashboardSidebar(
"Distribuciones muestrales", startExpanded = TRUE, tabName = "DM",
menuSubItem("TCL", tabName = "DM1")
),
menuItem("IC: Intervalos de confianza", tabName = "IC")#,
# menuItem(
# "Pruebas de Hipótesis", tabName = "PH", startExpanded = TRUE,
# menuSubItem("Para una media", tabName = "PH1"),
# menuSubItem("Para dos medias", tabName = "PH2"),
# menuSubItem("Para varianzas", tabName = "PH3")
# ),
menuItem("IC: Intervalos de confianza", tabName = "IC"),
menuItem("Pruebas de Hipótesis", tabName = "PH")#,
# menuItem(
# "Regresión Lineal", tabName = "RL", startExpanded = TRUE,
# menuSubItem("Simple", tabName = "RL1"),
Expand Down Expand Up @@ -117,12 +112,37 @@ cuerpo_IC = sidebarLayout(
)
)

simulador3 = actionButton(inputId = "go_PH", label = "Simular")

cuerpo_PH = sidebarLayout(
sidebarPanel(
width = 3,
radioButtons(inputId = "mediasPH", label = "Medias", choices = c("Una")),#, "Dos")),
radioButtons(inputId = "varianazasPH", label = "Varianzas", choices = c("Conocidas")),#, "Desconocidas")),
radioButtons(inputId = "tipoPH", label = "Tipo de prueba", choices = c("Bilateral", "Unilateral derecha", "Unilateral izquierda")),
sliderInput(inputId = "mu0PH", label = "Media bajo Hipótesis nula", min = -20, max = 20, value = 0, step = 0.1),
sliderInput(inputId = "sigma2PH", label = "Varianza poblacional", min = 1, max = 20, value = 6, step = 0.1),
sliderInput(inputId = "mediaMuestraPH", label = "Media muestral", min = -20, max = 20, value = 2, step = 0.1),
sliderInput(inputId = "nPH", label = "Tamaño muestral", min = 10, max = 200, value = 120, step = 10),
sliderInput(inputId = "confianzaPH", label = "% Confianza", min = 10, max = 99, value = 95, step = 1),
simulador3
),
mainPanel(
width = 9,
fluidRow(
column(width = 6, plotOutput("plot_ph")),
column(width = 6, plotOutput("plot_ic_ph"))
)
)
)

# Asignando los cuerpos por filtro
hoja_DM = tabItem(tabName = "DM1", fluidPage(cuerpo_DM1))
hoja_IC = tabItem(tabName = "IC", fluidPage(cuerpo_IC))
hoja_PH = tabItem(tabName = "PH", fluidPage(cuerpo_PH))

cuerpo = dashboardBody(
tabItems(hoja_DM, hoja_IC)
tabItems(hoja_DM, hoja_IC, hoja_PH)
)

# Despliegue general
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Aplicació web de conceptos básicos de Estadística
2 changes: 1 addition & 1 deletion docs/app.json

Large diffs are not rendered by default.

0 comments on commit f4184e2

Please sign in to comment.