Function: Estimated missing single-tailed data from Guassian distribution (one-side) for blue’s new brain data analysis.
Input: input variable, assume to be Guassian distribution, other distribution should be replace with kernel.
Description: Missing values were imputated by Guassian distribution based Kernel density estimation with symmetric property.
GuassianFillup<-function(input){
input<- as.vector(input)
data<-density(input)
peak<-data$x[which.max(data$y)]
bound5<-data$x[which.max(data$y)]-sd(input)
bound3<-data$x[which.max(data$y)]+sd(input)
bound5
bound3
NumA<-sum(input<=peak)
NumB<-sum(input>=peak)
if(NumA>NumB){
print(paste("Esitmated Peak=",round(peak,3),"please fill up N=",abs(NumA-NumB),"data point in the rigth side",sep=" "))
}else{
print(paste("Esitmated Peak=",round(peak,3),"please fill up N=",abs(NumA-NumB),"data point in the left side",sep=" "))
}
inputsim<-c(input[input>=peak],unlist(lapply(input[input>peak],function(x) 2*peak-x)))
sdsim<-sd(inputsim)
Max<-max(max(input)-peak,peak-min(input))
hist(input,breaks=100,xlim=c(peak-Max,peak+Max),prob=TRUE)
abline(h=0,lty=2,col="black",lwd=2)
abline(v=peak,lty=2,col="red",lwd=2)
lines(density(input, adjust=2), lty="dotted", col="darkgreen", lwd=2)
lines(density(rnorm(length(input),peak,sdsim), adjust=2), lty="dotted", col="darkblue", lwd=2)
legend("topright",legend = c("Estimated peak","Raw fitted density","Fill up density"),lty="dotted",lwd=2,col=c("red","darkgreen","darkblue"),bty = "n")
return(inputsim)
}
set.seed(146)
input<-rnorm(10000,0,1)
input<-input[input>-1.5]
result<-GuassianFillup(input)
## [1] "Esitmated Peak= -0.065 please fill up N= 1151 data point in the left side"
# please load the function GuassianFillup advanced and then use GuassianFillup(data) to esitmated missing cells.
# example:
# Simulated input data
# set.seed(146)
# input<-rnorm(10000,0,1)
# hist(input,breaks=100,xlim=c(peak-Max,peak+Max),prob=TRUE)
# input<-input[input>-1.5]
# GuassianFillup(input)