【问题标题】:Finding cutoff between two overlapping density plots找到两个重叠密度图之间的截止值
【发布时间】:2015-11-30 20:57:47
【问题描述】:

我有两个不同基因变体表达的样本数据:

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))

我通过它们的表达绘制了这两个基因型变体,并试图确定区分它们的测定的最佳截止值:

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") 

显然我可以使用“abline”函数找到两个密度之间的最佳截止值,但是有没有更简洁的方法来识别截止值?

【问题讨论】:

  • 所以您是通过两个密度具有相同值的点来定义截止点(假设恰好有一个这样的点),对吧?
  • 是的,正是——它们相互交叉的地方。
  • 类似,但有两点不同: 1、我尝试不使用ggplot。 2,我试图让 R 给我实际的交叉点数。
  • 检查接受的答案;只有最后一行是关于ggplot2,而你想要的点被命名为intersection.point

标签: r r-caret density-plot


【解决方案1】:

这是基于@Julius 提供的链接的答案:

A.density <- density(subset(df, genotype == "A")$value, from = min(df$value), to = max(df$value), n = 2^10)
B.density <- density(subset(df, genotype == "B")$value, from = min(df$value), to = max(df$value), n = 2^10)
intersection.point <- A.density$x[which(diff((A.density$y - B.density$y) > 0) != 0) + 1]

【讨论】:

  • 这是另一个更简单的解决方案,似乎更精确:library(pROC),一旦加载包,运行此命令:coords(roc(genotype,value), "b", ret="t")
猜你喜欢
  • 2022-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多