[R] Graphical presentation of logistic regression
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Wed Sep 14 14:10:34 CEST 2005
Frank E Harrell Jr wrote:
>>I
>>really nead to know how to invert a histogram and how to overlay this
>>with another histogram "the right way up".
>>
Flipping the last two numbers in par()$usr has this effect...
> From what you describe, that is a poor way to represent the model
> except for judging discrimination ability (if the model is calibrated
> well). Effect plots, odds ratio charts, and nomograms are better. See
> the Design package for details.
From the poor-diagnostics-R-us dept, here's something to work from:
logDiag <- function(x,y){
d0=x[y==0]
d1=x[y==1]
h0=hist(d0,plot=FALSE)
h1=hist(d1,plot=FALSE, breaks=h0$breaks)
# set the xlim so the stalactites dont hit the stalagmites:
plot(h0, ylim=c(0,max(c(h0$counts,h1$counts))*2))
pu=par()$usr
# flip the Y-axis limits
par(usr=pu[c(1,2,4,3)])
# draw the stalactites
lines(h1)
# reset axis
par(usr=pu)
}
sample:
xyd=data.frame(x=runif(1000),y=as.numeric(runif(1000)>.2))
logDiag(xyd$x,xyd$y)
lets just hope this plot isn't patented like that baseball diamond
plot a few years ago. My lawyer is ready...
Baz
More information about the R-help
mailing list