File size: 3,886 Bytes
defa05d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
library(shiny)
shinyServer(function(input,output,session){
  
  dt <- reactive({
    inFile <- input$file1
    if(is.null(inFile)) 
      dt <- read.table('datos.txt', header=T, sep='\t')
    else dt <- read.csv(inFile$datapath, header=input$header,
                        sep=input$sep)
  })
  
  observe({
    updateSelectInput(session, "variable", choices=names(dt())) 
  })
  
  observeEvent(input$variable, {
    column_levels <- as.character(sort(unique(dt()[[input$variable]])))
    updateSelectInput(session, "niveles", choices = column_levels)
  })
  
  output$inputData <- renderTable({
    inFile <- input$file1
    if(is.null(inFile)) 
      dt <- read.table('datos.txt', header=T, sep='\t')
    else dt <- read.csv(inFile$datapath, header=input$header, 
                        sep=input$sep)
    dt
  })
  
  
  output$appPlot <- renderPlot({
    inFile <- input$file1
    if(is.null(inFile)) 
      dt <- read.table('datos.txt', header=T, sep='\t')
    else dt <- read.csv(inFile$datapath, header=input$header, 
                        sep=input$sep)
    Niveles <- na.omit(dt[, input$variable])  # Para sacar los NA de la variable
    
    tabla <- table(Niveles)
    ptabla <- prop.table(tabla)
    xx <- barplot(ptabla, las=1, col='deepskyblue3',
                  ylab='Frecuencia relativa', 
                  xlab='Niveles', ylim=c(0, max(ptabla)+0.1))
    
    text(x=xx, y=ptabla, pos=3, cex=0.8, col="black",
         label=round(ptabla, 4))

  })
  
  output$consolidado <- renderTable({
    inFile <- input$file1
    if(is.null(inFile)) 
      dt <- read.table('datos.txt', header=T, sep='\t')
    else dt <- read.csv(inFile$datapath, header=input$header, 
                        sep=input$sep)
    y <- na.omit(dt[, input$variable])  # Para sacar los NA de la variable
    tabla <- table(y)
    x <- tabla[input$niveles]
    n <- sum(tabla)
    res <- cbind(x, n, x/n)
    colnames(res) <- c('N煤mero de 茅xitos', 
                       'N煤mero de casos', 
                       'Proporci贸n observada')
    res
  }, align='c', bordered = TRUE, digits=4)
  
  output$resul1 <- renderText({
    inFile <- input$file1
    if(is.null(inFile)) 
      dt <- read.table('datos.txt', header=T, sep='\t')
    else dt <- read.csv(inFile$datapath, header=input$header, sep=input$sep)
    dt <- na.omit(dt)  # Para eliminar obs con NA
    
    y <- na.omit(dt[, input$variable])  # Para sacar los NA de la variable
    tabla <- table(y)
    x <- tabla[input$niveles]
    n <- sum(tabla)
    ph <- prop.test(x=x, n=n, alternative=input$h0, 
                    conf.level=input$alfa, p=input$p0,
                    correct=input$correct)
    
    ph$statistic <- sign(ph$estimate - ph$null.value) * sqrt(ph$statistic)
    paste0('El estad铆stico de prueba es z0=', round(ph$statistic, 4),
           ' con un valor-P de ', round(ph$p.value, 2), '.')
})
  
  output$resul2 <- renderText({
    inFile <- input$file1
    if(is.null(inFile)) 
      dt <- read.table('datos.txt', header=T, sep='\t')
    else dt <- read.csv(inFile$datapath, header=input$header, sep=input$sep)
    dt <- na.omit(dt)  # Para eliminar obs con NA
    
    y <- na.omit(dt[, input$variable])  # Para sacar los NA de la variable
    tabla <- table(y)
    x <- tabla[input$niveles]
    n <- sum(tabla)
    ph <- prop.test(x=x, n=n, alternative=input$h0, 
                    conf.level=input$alfa, p=input$p0,
                    correct=input$correct)
    
    intervalo <- paste("(", round(ph$conf.int[1], digits=4),
                       ", ",
                       round(ph$conf.int[2], digits=4),
                       ").", sep='')
    paste0('El intervalo de confianza del ', 100*input$alfa,
           '% para proporci贸n poblacional es ',
           intervalo)
  })

})