Browse Source

añadir randomizado 1

master
marcelcosta 4 years ago
parent
commit
1e0c476568
1 changed files with 48 additions and 0 deletions
  1. +48
    -0
      invivos/app.R

+ 48
- 0
invivos/app.R

@ -3,6 +3,8 @@ library(ggplot2)
library(reshape2) library(reshape2)
library(openxlsx) library(openxlsx)
library(dplyr) library(dplyr)
library(car)
library(ggbeeswarm)
source("../../funcions.R") source("../../funcions.R")
# Define UI for application # Define UI for application
@ -25,6 +27,52 @@ ui <- fluidPage(
# Define server logic required to draw a histogram # Define server logic required to draw a histogram
server <- function(input, output) { server <- function(input, output) {
output$distPlot <- renderPlot({
df<-read.xlsx(input$file1$datapath)
up_cuttof<-400
low_cuttof<-50
df<-df[df$Volumen < up_cuttof & df$Volumen > low_cuttof,]
df["Mouse"]<-gsub("[a-zA-Z]", "", df$MouseID)
s<-shapiro.test(df$Volumen)[[2]]
ngroup<-5
ind.list<-list()
pval.list<-list()
lvn.list<-list()
test.list<-list()
for (data in 1:2000){
interr=T
while(interr == T){
ind<-sample(rep(1:ngroup, each=7), length(unique(df$Mouse)))
df_temp<-merge(df, data.frame("Mouse"=unique(df$Mouse), "group"=as.factor(ind)))
interr<-any(table(df_temp$group) < floor(nrow(df_temp)/5) | table(df_temp$group) > ceiling(nrow(df_temp)/5))
}
ind.list[[data]]<-df_temp[,c("MouseID","group")]
lvn.list[data]<-leveneTest(Volumen ~ group, data = df_temp[,3:4])[[2]][1]
if (s < 0.05){
k<-kruskal.test(df_temp$Volumen,df_temp$group)
test.list[data]<-k[[1]][1]
pval.list[data]<-k[[3]][1]
}else{
res.aov<-aov(Volumen~group, data=df_temp)
pval.list[data]<-summary(res.aov)[[1]][[5]][1]
test.list[data]<-summary(res.aov)[[1]][[4]][1]
}
}
index<-which(unlist(lvn.list) == min(unlist(lvn.list)[which(unlist(pval.list) %in% sort(unlist(pval.list), decreasing = T)[1:20])]))
df_def<-merge(df, ind.list[[index]])
ggplot(df_def, aes(group, Volumen))+
geom_boxplot(outlier.alpha = F)+
geom_jitter(width=0.25)+
geom_point(stat="summary", color="blue", size=3)+
lims(y=c(0,max(df_def$Volumen)+10))
})
output$downloadData <- downloadHandler( output$downloadData <- downloadHandler(
filename = function() { filename = function() {

Loading…
Cancel
Save