File size: 6,798 Bytes
0345d3f |
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
library(shiny)
shinyServer(function(input,output,session){
dt1 <- reactive({
inFile <- input$file1
if(is.null(inFile))
dt1 <- read.table('datos1.txt', header=T, sep='\t')
else dt1 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
})
dt2 <- reactive({
inFile <- input$file2
if(is.null(inFile))
dt2 <- read.table('datos2.txt', header=T, sep='\t')
else dt2 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
})
observe({
updateSelectInput(session, "variable", choices=names(dt1()))
})
observe({
updateSelectInput(session, "variable", choices=names(dt2()))
})
observeEvent(input$variable, {
column_levels <- as.character(sort(unique(dt1()[[input$variable]])))
updateSelectInput(session, "niveles", choices = column_levels)
})
observeEvent(input$variable, {
column_levels <- as.character(sort(unique(dt2()[[input$variable]])))
updateSelectInput(session, "niveles", choices = column_levels)
})
output$inputData1 <- renderTable({
inFile <- input$file1
if(is.null(inFile))
dt1 <- read.table('datos1.txt', header=T, sep='\t')
else dt1 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
dt1
})
output$inputData2 <- renderTable({
inFile <- input$file2
if(is.null(inFile))
dt2 <- read.table('datos2.txt', header=T, sep='\t')
else dt2 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
dt2
})
output$consolidado <- renderTable({
inFile <- input$file1
if(is.null(inFile))
dt1 <- read.table('datos1.txt', header=T, sep='\t')
else dt1 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
inFile <- input$file2
if(is.null(inFile))
dt2 <- read.table('datos2.txt', header=T, sep='\t')
else dt2 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
y1 <- na.omit(dt1[, input$variable]) # Para sacar los NA de la variable
y2 <- na.omit(dt2[, input$variable])
tabla1 <- table(y1)
tabla2 <- table(y2)
x1 <- tabla1[input$niveles]
x2 <- tabla2[input$niveles]
n1 <- sum(tabla1)
n2 <- sum(tabla2)
res <- cbind(c(x1, x2), c(n1, n2), c(x1, x2)/c(n1, n2))
colnames(res) <- c('N煤mero de 茅xitos',
'N煤mero de casos',
'Proporci贸n observada')
rownames(res) <- c('Base de datos # 1', 'Base de datos # 2')
res
}, align='c', rownames=TRUE, bordered=TRUE, digits=4)
output$appPlot <- renderPlot({
inFile <- input$file1
if(is.null(inFile))
dt1 <- read.table('datos1.txt', header=T, sep='\t')
else dt1 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
inFile <- input$file2
if(is.null(inFile))
dt2 <- read.table('datos2.txt', header=T, sep='\t')
else dt2 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
# Creando la particion
par(mfrow=c(1, 2))
# Primer barplot
Niveles <- na.omit(dt1[, 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),
main='Base de datos # 1')
text(x=xx, y=ptabla, pos=3, cex=0.8, col="black",
label=round(ptabla, 4))
# Segundo barplot
Niveles <- na.omit(dt2[, 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),
main='Base de datos # 2')
text(x=xx, y=ptabla, pos=3, cex=0.8, col="black",
label=round(ptabla, 4))
})
output$resul1 <- renderText({
inFile <- input$file1
if(is.null(inFile))
dt1 <- read.table('datos1.txt', header=T, sep='\t')
else dt1 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
inFile <- input$file2
if(is.null(inFile))
dt2 <- read.table('datos2.txt', header=T, sep='\t')
else dt2 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
y1 <- na.omit(dt1[, input$variable]) # Para sacar los NA de la variable
y2 <- na.omit(dt2[, input$variable])
tabla1 <- table(y1)
tabla2 <- table(y2)
x1 <- tabla1[input$niveles]
x2 <- tabla2[input$niveles]
n1 <- sum(tabla1)
n2 <- sum(tabla2)
ph <- prop.test(x=c(x1, x2), n=c(n1, n2),
alternative=input$h0,
conf.level=input$alfa,
correct=input$correct)
ph$statistic <- sign(ph$estimate[1] - ph$estimate[2]) * 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))
dt1 <- read.table('datos1.txt', header=T, sep='\t')
else dt1 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
inFile <- input$file2
if(is.null(inFile))
dt2 <- read.table('datos2.txt', header=T, sep='\t')
else dt2 <- read.csv(inFile$datapath, header=input$header,
sep=input$sep)
y1 <- na.omit(dt1[, input$variable]) # Para sacar los NA de la variable
y2 <- na.omit(dt2[, input$variable])
tabla1 <- table(y1)
tabla2 <- table(y2)
x1 <- tabla1[input$niveles]
x2 <- tabla2[input$niveles]
n1 <- sum(tabla1)
n2 <- sum(tabla2)
ph <- prop.test(x=c(x1, x2), n=c(n1, n2),
alternative=input$h0,
conf.level=input$alfa,
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)
})
})
|