Spaces:
Sleeping
Sleeping
FreddyHernandez
commited on
Upload 5 files
Browse files- include.html +0 -0
- include.md +27 -0
- means_data.txt +101 -0
- server.R +86 -0
- ui.R +107 -0
include.html
ADDED
The diff for this file is too large to render.
See raw diff
|
|
include.md
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Prueba de hip贸tesis para la media
|
2 |
+
|
3 |
+
Suponga que se tiene una muestra aleatoria $X_1, X_2, \ldots, X_n$ proveniente de una poblaci贸n normal. Se quiere estudiar la hip贸tesis nula $H_0: \mu = \mu_0$ y se sospecha que la media $\mu$ cumple una de las siguientes situaciones:
|
4 |
+
|
5 |
+
1. $H_a: \mu < \mu_0$
|
6 |
+
2. $H_a: \mu \neq \mu_0$
|
7 |
+
3. $H_a: \mu > \mu_0$
|
8 |
+
|
9 |
+
El estad铆stico para realizar la prueba es $$T_0=\frac{\bar{X} - \mu_0}{S/\sqrt{n}},$$
|
10 |
+
|
11 |
+
donde $\bar{X}$ y $S$ son la media y desviaci贸n est谩ndar muestral respectivamente.
|
12 |
+
|
13 |
+
Bajo la suposici贸n de que $H_0$ es verdadera, $T_0$ tiene distribuci贸n $t$-student con $n-1$ grados de libertad.
|
14 |
+
|
15 |
+
Si el valor calculado para el estad铆stico dado en la ecuaci贸n anterior se denota por $t_0$, entonces el valor-$P$ de la prueba se calcula de acuerdo a la hip贸tesis alterna $H_a$ as铆:
|
16 |
+
|
17 |
+
- Si $H_a: \mu < \mu_0$ entonces valor-$P$=$P(t_{n-1} < t_0)$.
|
18 |
+
- Si $H_a: \mu \neq \mu_0$ entonces valor-$P$=$2 \times P(t_{n-1} > \lvert t_0 \rvert)$.
|
19 |
+
- Si $H_a: \mu > \mu_0$ entonces valor-$P$=$P(t_{n-1} > t_0)$.
|
20 |
+
|
21 |
+
Si se d谩 el caso en que la muestra aleatoria no proviene de una poblaci贸n normal pero se cumple que $n \geq 40$, entonces el estad铆stico para realizar la prueba es:
|
22 |
+
$$
|
23 |
+
Z_0=\frac{\bar{X} - \mu_0}{S/\sqrt{n}},
|
24 |
+
$$
|
25 |
+
y en este caso el estad铆stico $Z_0$, en virtud del Teorema del L铆mite Central, tiene una distribuci贸n $z \sim N(0, 1)$ bajo la suposici贸n de que $H_0$ es verdadera. Si el valor calculado del estad铆stico es $z_0$, se pueden usar las expresiones anteriores para calcular el valor-$P$ sustituyendo $t_0$ por $z_0$ y $t_{n-1}$ por $z$.
|
26 |
+
|
27 |
+
En cualquiera de los casos, la hip贸tesis nula $H_0$ se rechaza si el valor-$P$ es menor que el nivel de significancia ($\alpha$) fijado previamente por el analista.
|
means_data.txt
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Weigth Heigth
|
2 |
+
53.09817 168.9792
|
3 |
+
60.2536 154.0794
|
4 |
+
60.57112 178.5135
|
5 |
+
53.55212 145.6071
|
6 |
+
63.95424 145.1823
|
7 |
+
68.62175 146.6526
|
8 |
+
59.3937 150.1703
|
9 |
+
54.85139 154.1393
|
10 |
+
56.18212 211.1142
|
11 |
+
57.94596 155.6074
|
12 |
+
60.05633 180.7278
|
13 |
+
56.65037 153.8238
|
14 |
+
59.14473 160.6151
|
15 |
+
60.85186 172.8011
|
16 |
+
63.4691 168.2495
|
17 |
+
68.87719 190.7063
|
18 |
+
53.22856 193.0385
|
19 |
+
61.98031 152.1141
|
20 |
+
61.3466 178.4211
|
21 |
+
70.6553 162.0479
|
22 |
+
53.94735 138.9784
|
23 |
+
65.30227 178.686
|
24 |
+
67.90827 177.2521
|
25 |
+
60.19456 182.7935
|
26 |
+
63.14799 168.6113
|
27 |
+
50.74211 161.106
|
28 |
+
54.37209 149.4436
|
29 |
+
61.80647 162.5439
|
30 |
+
66.44006 204.6559
|
31 |
+
69.32612 180.8448
|
32 |
+
56.43465 166.6911
|
33 |
+
59.92681 162.9765
|
34 |
+
67.89035 159.6578
|
35 |
+
50.20544 162.7743
|
36 |
+
65.17708 162.8984
|
37 |
+
64.21323 189.4598
|
38 |
+
60.07455 150.462
|
39 |
+
57.61265 148.8138
|
40 |
+
66.2314 176.9834
|
41 |
+
53.15213 182.6959
|
42 |
+
56.11033 161.2404
|
43 |
+
55.2948 190.1691
|
44 |
+
60.50972 169.5429
|
45 |
+
63.83561 148.3607
|
46 |
+
65.33804 164.7481
|
47 |
+
54.50226 167.4611
|
48 |
+
65.59086 174.1593
|
49 |
+
55.52423 167.5852
|
50 |
+
67.02337 175.3402
|
51 |
+
62.62035 170.9605
|
52 |
+
68.87993 170.869
|
53 |
+
53.89413 169.9824
|
54 |
+
54.96583 172.2888
|
55 |
+
52.12436 188.0458
|
56 |
+
50.40455 196.4013
|
57 |
+
62.84082 165.8279
|
58 |
+
56.22349 155.3835
|
59 |
+
57.65475 156.3143
|
60 |
+
61.75107 175.7196
|
61 |
+
60.88272 170.8627
|
62 |
+
62.35261 170.2354
|
63 |
+
60.57066 176.973
|
64 |
+
63.32021 181.3175
|
65 |
+
68.06532 184.0032
|
66 |
+
62.78009 165.8424
|
67 |
+
52.65252 182.4191
|
68 |
+
66.70305 154.5413
|
69 |
+
51.62308 145.1807
|
70 |
+
56.02632 178.2507
|
71 |
+
57.55016 155.53
|
72 |
+
59.998 209.5686
|
73 |
+
62.53957 140.5118
|
74 |
+
61.46648 167.0732
|
75 |
+
70.13264 166.7734
|
76 |
+
60.09332 177.3142
|
77 |
+
61.39649 158.3873
|
78 |
+
60.20784 175.4754
|
79 |
+
51.45882 153.2652
|
80 |
+
49.993 163.1174
|
81 |
+
61.18023 150.3906
|
82 |
+
55.6152 161.9006
|
83 |
+
61.40898 149.1997
|
84 |
+
57.55849 180.9661
|
85 |
+
55.819 178.2533
|
86 |
+
59.39731 176.8483
|
87 |
+
59.94743 150.9343
|
88 |
+
56.59401 146.71
|
89 |
+
68.53324 175.1023
|
90 |
+
62.87226 173.1839
|
91 |
+
65.50766 169.1627
|
92 |
+
61.04492 168.7064
|
93 |
+
62.38285 185.0806
|
94 |
+
55.54364 162.3449
|
95 |
+
53.17127 175.9443
|
96 |
+
56.12465 162.7634
|
97 |
+
63.39455 182.122
|
98 |
+
61.88589 140.1003
|
99 |
+
67.47816 154.0689
|
100 |
+
60.24467 184.4114
|
101 |
+
64.1793 171.2866
|
server.R
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
library(shiny)
|
2 |
+
|
3 |
+
shinyServer(function(input,output,session){
|
4 |
+
|
5 |
+
observe({
|
6 |
+
inFile <- input$file1
|
7 |
+
if(is.null(inFile))
|
8 |
+
dt <- read.table('means_data.txt', header=T, sep='\t')
|
9 |
+
else dt <- read.csv(inFile$datapath, header=input$header,
|
10 |
+
sep=input$sep)
|
11 |
+
updateSelectInput(session, "variable", choices=names(dt))
|
12 |
+
})
|
13 |
+
|
14 |
+
output$inputData <- renderTable({
|
15 |
+
inFile <- input$file1
|
16 |
+
if(is.null(inFile))
|
17 |
+
dt <- read.table('means_data.txt', header=T, sep='\t')
|
18 |
+
else dt <- read.csv(inFile$datapath, header=input$header,
|
19 |
+
sep=input$sep)
|
20 |
+
dt
|
21 |
+
})
|
22 |
+
|
23 |
+
output$statistic <- renderTable({
|
24 |
+
inFile <- input$file1
|
25 |
+
if(is.null(inFile))
|
26 |
+
dt <- read.table('means_data.txt', header=T, sep='\t')
|
27 |
+
else dt <- read.csv(inFile$datapath, header=input$header,
|
28 |
+
sep=input$sep)
|
29 |
+
y <- na.omit(dt[, input$variable]) # Para sacar los NA de la variable
|
30 |
+
res <- data.frame(Media=mean(y), Varianza=var(y), n=length(y))
|
31 |
+
colnames(res) <- c('Media', 'Varianza', 'N煤mero obs')
|
32 |
+
res
|
33 |
+
}, align='c', bordered = TRUE)
|
34 |
+
|
35 |
+
output$appPlot <- renderPlot({
|
36 |
+
inFile <- input$file1
|
37 |
+
if(is.null(inFile))
|
38 |
+
dt <- read.table('means_data.txt', header=T, sep='\t')
|
39 |
+
else dt <- read.csv(inFile$datapath, header=input$header,
|
40 |
+
sep=input$sep)
|
41 |
+
y <- na.omit(dt[, input$variable]) # Para sacar los NA de la variable
|
42 |
+
|
43 |
+
par(mfrow=c(1, 2), bg='gray98')
|
44 |
+
hist(y, col='deepskyblue3', freq=F, las=1,
|
45 |
+
xlab=as.character(input$variable),
|
46 |
+
main='Histograma y densidad', ylab='Densidad')
|
47 |
+
lines(density(y), lwd=4, col='firebrick3')
|
48 |
+
qqnorm(y, las=1, main='QQplot', xlab='Cuantiles te贸ricos N(0, 1)',
|
49 |
+
pch=19, col='deepskyblue3',
|
50 |
+
ylab=as.character(input$variable))
|
51 |
+
qqline(y)
|
52 |
+
shapi <- shapiro.test(x=y)
|
53 |
+
legend('topleft', bty='n', col='red', text.col='deepskyblue3',
|
54 |
+
legend=paste('Valor P=', round(shapi$p.value, 2)))
|
55 |
+
})
|
56 |
+
|
57 |
+
output$resul1 <- renderText({
|
58 |
+
inFile <- input$file1
|
59 |
+
if(is.null(inFile))
|
60 |
+
dt <- read.table('means_data.txt', header=T, sep='\t')
|
61 |
+
else dt <- read.csv(inFile$datapath, header=input$header,
|
62 |
+
sep=input$sep)
|
63 |
+
y <- na.omit(dt[, input$variable]) # Para sacar los NA de la variable
|
64 |
+
ph <- t.test(x=y, alternative=input$h0, mu=input$mu0,
|
65 |
+
conf.level=input$alfa)
|
66 |
+
paste0('El estad铆stico de prueba es to=', round(ph$statistic, 2),
|
67 |
+
' con un valor-P de ', round(ph$p.value, 4), '.')
|
68 |
+
})
|
69 |
+
|
70 |
+
output$resul2 <- renderText({
|
71 |
+
inFile <- input$file1
|
72 |
+
if(is.null(inFile))
|
73 |
+
dt <- read.table('means_data.txt', header=T, sep='\t')
|
74 |
+
else dt <- read.csv(inFile$datapath, header=input$header,
|
75 |
+
sep=input$sep)
|
76 |
+
y <- na.omit(dt[, input$variable]) # Para sacar los NA de la variable
|
77 |
+
ph <- t.test(x=y, alternative=input$h0, mu=input$mu0,
|
78 |
+
conf.level=input$alfa)
|
79 |
+
intervalo <- paste("(", round(ph$conf.int[1], digits=4), ", ",
|
80 |
+
round(ph$conf.int[2], digits=4), ").", sep='')
|
81 |
+
paste0('El intervalo de confianza del ', 100*input$alfa,
|
82 |
+
'% para la media poblacional es ', intervalo)
|
83 |
+
})
|
84 |
+
|
85 |
+
|
86 |
+
})
|
ui.R
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
library(shiny)
|
2 |
+
library(markdown)
|
3 |
+
|
4 |
+
shinyUI(pageWithSidebar(
|
5 |
+
headerPanel(title=HTML("Prueba de hip贸tesis para la media μ"),
|
6 |
+
windowTitle="PH media"),
|
7 |
+
sidebarPanel(
|
8 |
+
h5('Esta aplicaci贸n realiza la prueba de hip贸tesis para la
|
9 |
+
media de una variable cuantitativa con distribuci贸n normal.'),
|
10 |
+
|
11 |
+
h6('La aplicaci贸n usa una base de datos de ejemplo pero el usuario
|
12 |
+
puede cargar su propia base de datos.'),
|
13 |
+
|
14 |
+
fileInput(inputId='file1',
|
15 |
+
label='Use el siguiente bot贸n para cargar su base de datos.',
|
16 |
+
accept = c(
|
17 |
+
'text/csv',
|
18 |
+
'text/comma-separated-values',
|
19 |
+
'text/tab-separated-values',
|
20 |
+
'text/plain',
|
21 |
+
'.csv',
|
22 |
+
'.tsv'
|
23 |
+
)),
|
24 |
+
|
25 |
+
checkboxInput(inputId='header',
|
26 |
+
label='驴Tiene encabezado la base de datos?',
|
27 |
+
value=TRUE),
|
28 |
+
|
29 |
+
selectInput(inputId="sep",
|
30 |
+
label = "驴Cu谩l es la separaci贸n de los datos?",
|
31 |
+
choices = list(Tab='\t', Comma=',',
|
32 |
+
Semicolon=';', 'Space'=' '),
|
33 |
+
selected = ';'),
|
34 |
+
|
35 |
+
selectInput(inputId="variable",
|
36 |
+
label="Elija la variable cuantitativa para realizar
|
37 |
+
la prueba de hip贸tesis.",
|
38 |
+
choices=""),
|
39 |
+
|
40 |
+
numericInput(inputId='mu0',
|
41 |
+
label=HTML("Ingrese el valor de referencia
|
42 |
+
μ<sub>0</sub> para probar
|
43 |
+
H<sub>0</sub>: μ = μ<sub>0</sub>"),
|
44 |
+
value=60),
|
45 |
+
|
46 |
+
selectInput(inputId="h0",
|
47 |
+
label=HTML("Elija la hip贸tesis alternativa
|
48 |
+
< , ≠ o >"),
|
49 |
+
choices=list("Menor" = "less",
|
50 |
+
"Diferente" = "two.sided",
|
51 |
+
"Mayor" = "greater"),
|
52 |
+
selected = "two.sided"),
|
53 |
+
|
54 |
+
sliderInput(inputId='alfa',
|
55 |
+
label=HTML("Opcional: elija un nivel de confianza para
|
56 |
+
construir el intervalo de confianza para la media μ"),
|
57 |
+
min=0.90, max=0.99,
|
58 |
+
value=0.95, step=0.01),
|
59 |
+
|
60 |
+
img(src="https://raw.githubusercontent.com/fhernanb/fhernanb.github.io/refs/heads/main/my_docs/logo_unal_shiny.png",
|
61 |
+
height = 60, width = 120),
|
62 |
+
img(src="https://raw.githubusercontent.com/fhernanb/fhernanb.github.io/refs/heads/main/my_docs/logo_udea_shiny.png",
|
63 |
+
height = 25, width = 70),
|
64 |
+
img(src="https://raw.githubusercontent.com/fhernanb/fhernanb.github.io/refs/heads/main/my_docs/logo_cua_shiny.png",
|
65 |
+
height = 40, width = 110),
|
66 |
+
br(),
|
67 |
+
tags$a(href="https://srunal.github.io", "https://srunal.github.io")
|
68 |
+
|
69 |
+
),
|
70 |
+
|
71 |
+
mainPanel(
|
72 |
+
tabsetPanel(type = "pills",
|
73 |
+
|
74 |
+
tabPanel("Resultados",
|
75 |
+
h5('A continuaci贸n el histograma, ladensidad,
|
76 |
+
el QQplot
|
77 |
+
y valor-P de la prueba de normalidad
|
78 |
+
Shapiro-Wilk para la muestra.'),
|
79 |
+
|
80 |
+
plotOutput("appPlot",
|
81 |
+
width='500px',
|
82 |
+
height='300px'),
|
83 |
+
|
84 |
+
h4("- Tabla de resumen con estad铆sticos los muestrales:"),
|
85 |
+
tableOutput('statistic'),
|
86 |
+
|
87 |
+
h4("- Resultados de la prueba de hip贸tesis:"),
|
88 |
+
textOutput("resul1"),
|
89 |
+
|
90 |
+
h4(HTML("- Intervalo de confianza para la media μ:")),
|
91 |
+
textOutput("resul2")),
|
92 |
+
|
93 |
+
tabPanel("Datos",
|
94 |
+
"A continuaci贸n los datos que est谩 usando
|
95 |
+
la aplicaci贸n.",
|
96 |
+
uiOutput('inputData')),
|
97 |
+
|
98 |
+
tabPanel("Teor铆a", includeHTML("include.html"))
|
99 |
+
|
100 |
+
)
|
101 |
+
)
|
102 |
+
|
103 |
+
))
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
|