File size: 3,354 Bytes
bc8a8e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
library(shiny)

shinyServer(function(input,output,session){
  
  observe({
    inFile <- input$file1
    if(is.null(inFile)) 
      dt <- read.table('means_data.txt', header=T, sep='\t')
    else dt <- read.csv(inFile$datapath, header=input$header,
                        sep=input$sep)
    updateSelectInput(session, "variable", choices=names(dt))
  })
  
  output$inputData <- renderTable({
    inFile <- input$file1
    if(is.null(inFile)) 
      dt <- read.table('means_data.txt', header=T, sep='\t')
    else dt <- read.csv(inFile$datapath, header=input$header, 
                        sep=input$sep)
    dt
  })
  
  output$statistic <- renderTable({
    inFile <- input$file1
    if(is.null(inFile)) 
      dt <- read.table('means_data.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
    res <- data.frame(Media=mean(y), Varianza=var(y), n=length(y))
    colnames(res) <- c('Media', 'Varianza', 'Número obs')
    res
  }, align='c', bordered = TRUE)
  
  output$appPlot <- renderPlot({
    inFile <- input$file1
    if(is.null(inFile)) 
      dt <- read.table('means_data.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
    
    par(mfrow=c(1, 2), bg='gray98')
    hist(y, col='deepskyblue3', freq=F, las=1,
         xlab=as.character(input$variable),
         main='Histograma y densidad', ylab='Densidad')
    lines(density(y), lwd=4, col='firebrick3')
    qqnorm(y, las=1, main='QQplot', xlab='Cuantiles teóricos N(0, 1)',
           pch=19, col='deepskyblue3',
           ylab=as.character(input$variable))
    qqline(y)
    shapi <- shapiro.test(x=y)
    legend('topleft', bty='n', col='red', text.col='deepskyblue3',
           legend=paste('Valor P=', round(shapi$p.value, 2)))
  })
  
  output$resul1 <- renderText({
    inFile <- input$file1
    if(is.null(inFile)) 
      dt <- read.table('means_data.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
    ph <- t.test(x=y, alternative=input$h0, mu=input$mu0, 
                 conf.level=input$alfa)
    paste0('El estadístico de prueba es to=', round(ph$statistic, 2),
           ' con un valor-P de ', round(ph$p.value, 4), '.')
  })
  
   output$resul2 <- renderText({
     inFile <- input$file1
     if(is.null(inFile)) 
       dt <- read.table('means_data.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
    ph <- t.test(x=y, alternative=input$h0, mu=input$mu0, 
                 conf.level=input$alfa)
    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 la media poblacional es ', intervalo)
  })
   

})