I have this sample data of expression of two different gene variants:
value<-cbind(c(rnorm(100,500,90),rnorm(100,800,120)))
genotype<-cbind(c(rep("A",100),rep("B",100)))
df<-cbind(value,genotype)
df<-as.data.frame(df)
colnames(df)<-c("value","genotype")
df$value<-as.numeric(as.character(df$value))
I plotted these two genotype variants by their expression and am trying to determine the optimal cutoff value of the assay that differentiates between them:
d <- density(value)
plot(d, main="Genotypes A and B", ,type="n",xlim=c(200,1100),ylim=c(0,0.005),xlab="Units of expression",ylab="")
d1 <- density(subset(value,genotype=="A"))
polygon(d1, col = adjustcolor('gray', alpha.f = .40), border="black")
d2 <- density(subset(value,genotype=="B"))
polygon(d2, col = adjustcolor('gray', alpha.f = .40), border="black")
Obviously I can use "abline" function to find the best cutoff between the two densities, but is there a neater way to identify the cutoff?