Skip to content

Conditioning plots (wth coplot function) with logistic regression curves

4 messages · Kiyoshi Sasaki, Michael Friendly

#
On 9/21/2013 11:12 PM, Kiyoshi Sasaki wrote:
If you feel it hurts because you are banging your head into a wall 
trying to get coplot to do this, the answer is: Don't do that!

Instead, you might consider using ggplot2, which handles this case
nicely, as far as I can tell from your description.

But first a due diligence caveat:  Say you come to me for consulting
on this little plotting question. I look at your data frame, dat,
and I see there are a number of other variables that might explain
Presence, so maybe the marginal plot that ignores them could be
misleading, e.g., any of Moist, Leaf, Prey, ... could moderate
the relation between overstory and presence, but you won't see that
in a marginal plot.


Here are a couple of quick ggplot examples, plotting classes of Ivy in the
same plot frame, and on the probability scale.

library(ggplot2)
ggplot(dat, aes(Overstory, Presence), color=Ivy>50 ) +
   stat_smooth(method="glm", family=binomial, formula= y~x, alpha=0.3, 
aes(fill=Ivy>50))

dat$Ivy3 <- factor(cut(dat$Ivy,3))
plt <- ggplot(dat, aes(Overstory, Presence), color=Ivy3 ) +
   stat_smooth(method="glm", family=binomial, formula= y~x, alpha=0.3, 
aes(fill=Ivy3))
plt

If you want separate panels, try something like

plt + facet_grid(. ~ Ivy3)

For plots on the logit scale, try something like
logit <- function(p) log(p)/log(1-p), then

plt + coord_trans(y="logit")