我有一些二进制数据,希望能够在同一张图上绘制逻辑回归线和相对频率为0和1的直方图。
我找到了一个非常好的实现方式,使用popbio包,这里是shizuka lab的页面:shizuka lab's page
以下是一个使用library(popbio)运行的最小化工作示例(由shizuka lab提供):
bodysize=rnorm(20,30,2) # generates 20 values, with mean of 30 & s.d.=2
bodysize=sort(bodysize) # sorts these values in ascending order.
survive=c(0,0,0,0,0,1,0,1,0,0,1,1,0,1,1,1,0,1,1,1) # assign 'survival' to these 20 individuals non-randomly... most mortality occurs at smaller body size
dat=as.data.frame(cbind(bodysize,survive))
#and now the plot
library(popbio)
logi.hist.plot(bodysize,survive,boxp=FALSE,type="hist",col="gray")
这将会产生: