#install.packages("ggplot2") |
#install.packages("Rmisc") |
#install.packages("rio") |
require(ggplot2) |
require(Rmisc) |
require(rio) |
setwd("C:\\Users\\PC\\Dropbox\\Trabalho\\W") |
data=read.table("Results.txt",head=TRUE) #Import Result.txt file |
#data=read.table(file.choose(),head=TRUE) #Import Result.txt file |
#Significance Level |
threshold=seq(from=0.2, to=0.99, by=0.02) #Threshold limits |
####### Organizes the data set, performs the neuron count and applies the Wilcoxon test ###### |
i=1 |
while(i <= nrow(data)){ |
data[i,6]=data[i+1,5]/data[i,5] |
|
} |
data<- subset(data, !is.na(data[,6])) |
l |
for( in 1:length(threshold)){ |
for( in 1:nrow(data)){ |
if() |
|
else |
|
} |
aggre1=aggregate(data[,7], by=list(data[,1],data[,2]), sum) |
if(){ |
result.graph=data.frame(matrix(NA, ncol=3, nrow=nrow(aggre1)length(threshold))) |
result.count=data.frame(matrix(NA, ncol=(length(threshold)+2), nrow=nrow(aggre1))) |
result.wilcoxon=data.frame(matrix(NA, ncol=3, nrow=length(threshold))) |
result.count[,1]=aggre1[,1];result.count[,2]=aggre1[,2] |
colnames(result.graph)=c("Animals","X","Threshold") |
colnames(result.wilcoxon)=c("Threshold","W","p-value") |
colnames(result.count)=c("Type","Slice",paste("Threshold", threshold100,sep="")) |
} |
result.count[,j+2]=aggre1[,3] |
for( in 1:nrow(aggre1)){ |
if() |
result.graph[l,1]="EXP" |
else |
result.graph[l,1]="CTRL" |
result.graph[l,2]=aggre1[k,3] |
result.graph[l,3]=threshold[j]100 |
w=wilcox.test(aggre1[aggre1[,1]==1,3], aggre1[aggre1[,1]==2,3],alternative="two.side") |
result.wilcoxon[j,1]=threshold[j]100; result.wilcoxon[j,2]=w$statistic; result.wilcoxon[j,3]=w$.value |
|
} |
} |
#Export file with Wilcoxon test results |
export(result.wilcoxon, file = "Result_Wilcoxon.xlsx", overwrite = TRUE) |
#resultados das contagens |
export(result.count, file = "Result_Contagem.xlsx", overwrite = TRUE) |
################### Averages Chart ################### |
tgc <- summarySE(result.graph, measurevar="X", groupvars=c("Animals","Threshold")) |
ggplot(tgc, aes(x=Threshold, y=X, colour=Animals)) + |
labs(x="Background percentage threshold (%)") + |
labs(y="Average number of the core count of c-Fos-positive neurons") + |
geom_errorbar(aes(ymin=X-se, ymax=X+se), colour="black", width=1) + |
theme_bw() + |
geom_point(aes(shape=Animals),size=3, colour="black") + |
annotate("text", x = result.wilcoxon[result.wilcoxon[,3]<sig,1], |
y = tgc[tgc$Threshold >= min(result.wilcoxon[result.wilcoxon[,3]<sig,1]) & |
tgc$Threshold <= max(result.wilcoxon[result.wilcoxon[,3]<sig,1]) & tgc$Animals=="EXP",4]+ |
tgc[tgc$Threshold >= min(result.wilcoxon[result.wilcoxon[,3]<sig,1]) & |
tgc$Threshold <= max(result.wilcoxon[result.wilcoxon[,3]<sig,1]) & tgc$Animals=="EXP",6]+1 |
label = "", cex=6) |
ggsave(filename = "Average number of the core count of c-Fos-positive neurons.tiff", |
, ) |
################### Graphic -valor ################### |
tiff(filename = " value vs Background percentage threshold.tiff") |
plot(result.wilcoxon[,3] ~ result.wilcoxon[,1], type="p", pch=20, |
xlab="Background percentage threshold (%)", ylab=" value") |
lines(c(sig, sig)~c(result.wilcoxon[1],result.wilcoxon[length(result.wilcoxon[,1]),1]), lty=3) |
dev.off() |
############# Nonlinear Regression ######################### |
tgc <- summarySE(result.graph, measurevar="X", groupvars=c("Animals","Threshold")) |
tgc2=subset(tgc, tgc$Animals=="EXP") |
reg=as.data.frame(matrix(NA, ncol=4, nrow=3)) |
colnames(reg)=c("Parameters", "Estimate", "Std. Error", "Pr(>|t|)") |
y=tgc2$X |
x=tgc2$Threshold |
, |
mod=summary(result) |
reg[,1]=rownames(mod$coefficients) |
reg[,2]=mod$coefficients[,1] |
reg[,3]=mod$coefficients[,2] |
reg[,4]=mod$coefficients[,4] |
reg[1, 5]="Inflection Point" |
reg[1, 6]="Count of c-Fos-positive neurons" |
reg[1, 7]="Background percentage threshold (%)" |
reg[2, 6]=mod$coefficients[1]/2 |
reg[2, 7]=-mod$coefficients[2]/mod$coefficients[3] |
export(reg, file = "Result_Non_Linear_Regression.xlsx", overwrite = TRUE) |
## |
tgc2[,8]=mod$coefficients[1]/(1+exp(-(mod$coefficients[2]+mod$coefficients[3]x))) |
colnames(tgc2)[8]="est" |
# Gr?fico com todos os grupos |
ggplot(tgc, aes(x=Threshold, y=X, colour=Animals)) + |
labs(x="Background percentage threshold (%)") + |
labs(y="Average number of the core count of c-Fos-positive neurons") + |
geom_errorbar(aes(ymin=X-se, ymax=X+se), colour="black", width=1) + |
theme_bw() + |
xlim(min(tgc2$Threshold)-2, max(tgc2$Threshold)+2) + |
geom_point(aes(shape=Animals),size=3, colour="black") + |
geom_line(data = tgc2, aes(x = Threshold, y = est), size =1.5, color="red") + |
geom_segment(aes(x = reg[2, 7], y = 0, xend = reg[2, 7], yend = reg[2, 6]), |
size=1, colour="red", linetype = "dashed") + |
geom_segment(aes(x = min(tgc2$Threshold)-2, y = reg[2, 6], xend = reg[2, 7], |
yend = reg[2, 6]),, colour="red", linetype = "dashed") |
ggsave(filename = "Nonlinear Regression Adjustment.tiff", |
, ) |