Spaces:
Sleeping
Sleeping
File size: 5,639 Bytes
6fa3119 |
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 |
library(shiny)
source("auxiliar.R")
shinyServer(function(input,output,session){
observe({
inFile <- input$file1
if(is.null(inFile))
dt <- datos
else dt <- read.csv(inFile$datapath, header=input$header, sep=input$sep)
updateSelectInput(session, "variable1",
choices = names(dt),
selected = "Weight")
updateSelectInput(session, "variable2",
choices = names(dt),
selected = "Group")
})
output$summary <- renderTable({
inFile <- input$file1
if(is.null(inFile))
dt <- datos
else dt <- read.csv(inFile$datapath, header=input$header, sep=input$sep)
dt <- na.omit(dt) # Para eliminar obs con NA
dt
})
output$appPlot <- renderPlot({
inFile <- input$file1
if(is.null(inFile))
dt <- datos
else dt <- read.csv(inFile$datapath, header=input$header, sep=input$sep)
# Para eliminar obs con NA
dt <- na.omit(dt)
# Para obtener x y grupo
x <- dt[, input$variable1]
group <- dt[, input$variable2]
group <- as.factor(group)
if (nlevels(group) != 2) {
plot(1, type = "n", xlab = "", ylab = "", axes = FALSE)
mensaje <- "La variable cualitativa \n que eligi贸 debe tener s贸lo \n 2 niveles."
text(x=1, y=1, mensaje, cex=2, col = "blue", pos=3)
}
else {
par(mfrow=c(1, 2), bg="gray98")
# Para dibujar las densidades
xx <- split(x, group)
den <- lapply(xx, density)
plot(den[[1]], lwd=4, col="deepskyblue3",
main="Densidad", las=1,
xlab=as.character(input$variable1),
ylab="Densidad",
xlim=range(range(den[[1]]$x), range(den[[2]]$x)),
ylim=c(0, max(c(den[[1]]$y, den[[2]]$y))))
lines(den[[2]], lwd=4, col="firebrick3")
# Leyenda para distinguir las densidades
legend("topright", bty="n",
lwd=4,
col=c("deepskyblue3", "firebrick3"),
legend=unique(group))
# Para dibujar los qqplot
qq1 <- qqnorm(xx[[1]], plot.it=FALSE)
qq2 <- qqnorm(xx[[2]], plot.it=FALSE)
plot(qq1, las=1, main="QQplot",
pch=19, col="deepskyblue3",
xlim=range(c(qq1$x, qq2$x)),
ylim=range(c(qq1$y, qq2$y)),
xlab="Cuantiles te贸ricos N(0, 1)",
ylab=as.character(input$variable1))
points(qq2, pch=19, col="firebrick3")
# Para construir los qqplot
qqline(xx[[1]], col="deepskyblue3")
qqline(xx[[2]], col="firebrick3")
# Para incluir el valor P de Shapiro
shapi <- lapply(xx, shapiro.test)
leyenda <- c(paste("Valor P=", round(shapi[[1]]$p.value, 2)),
paste("Valor P=", round(shapi[[2]]$p.value, 2)))
legend("topleft", bty="n",
text.col=c("deepskyblue3", "firebrick3"),
legend=leyenda)
}
})
output$statistic <- renderTable({
inFile <- input$file1
if(is.null(inFile))
dt <- datos
else dt <- read.csv(inFile$datapath, header=input$header, sep=input$sep)
# Para eliminar obs con NA
dt <- na.omit(dt)
# Para obtener x y grupo
x <- dt[, input$variable1]
group <- dt[, input$variable2]
group <- as.factor(group)
xx <- split(x, group) # Lista con variable interes
resumen <- function(x) c(mean(x), var(x), length(x))
res <- sapply(xx, resumen)
rownames(res) <- c("Media", "Varianza", "N煤mero de observaciones")
t(res)
}, rownames = TRUE, align="c", bordered = TRUE)
output$resul1 <- renderText({
inFile <- input$file1
if(is.null(inFile))
dt <- datos
else dt <- read.csv(inFile$datapath, header=input$header, sep=input$sep)
# Para eliminar obs con NA
dt <- na.omit(dt)
# Para obtener x y grupo
x <- dt[, input$variable1]
group <- dt[, input$variable2]
group <- as.factor(group)
if (nlevels(group) != 2) {
paste0("La variable cualitativa \n que eligi贸 debe tener s贸lo \n 2 niveles.")
}
else {
xx <- split(x, group)
ph <- var.test(x=xx[[1]], y=xx[[2]],
alternative=input$h0,
ratio=1,
conf.level=input$alfa)
paste0('El estad铆stico de prueba es f0=', 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 <- datos
else dt <- read.csv(inFile$datapath, header=input$header, sep=input$sep)
dt <- na.omit(dt) # Para eliminar obs con NA
x <- dt[, input$variable1]
group <- dt[, input$variable2]
group <- as.factor(group)
if (nlevels(group) != 2) {
paste0("La variable cualitativa \n que eligi贸 debe tener s贸lo \n 2 niveles.")
}
else {
xx <- split(x, group)
ph <- var.test(x=xx[[1]], y=xx[[2]],
alternative=input$h0,
ratio=1,
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 el cociente de varianzas poblacionales es ',
intervalo)
}
})
}) |