# [R] Regression lines for differently-sized groups on the same plot

Laura M Marx marxlau1 at msu.edu
Wed Jul 20 19:58:37 CEST 2005

```Sundar Dorai-Raj writes:

> Hi, Laura,
>
> Would ?predict.glm be better?
>
> plot(logarea, hempresence,
>      xlab = "Surface area of log (m2)",
>      ylab="Probability of hemlock seedling presence",
>      type="n", font.lab=2, cex.lab=1.5, axes=TRUE)
> lines(logarea, predict(hemhem, logreg, "response"), lty=1, lwd=2)
> lines(logarea, predict(hemyb, logreg, "response"), lty="dashed", lwd=2)
> lines(logarea, predict(hemsm, logreg, "response"), lty="dotted", lwd=2)
>
> Without seeing more description of your data, this is still a guess.
>
> --sundar
>

YES!  Thank you.  That solves all of the problems I was having.  Thanks also
to Tom Mulholland and Bill Venables for their replies.
Laura
The final code is now:

#This is the full dataset.  A hemlock row followed by a birch row might look
#like:
#Hemybsm     logarea    hempresence
#1           0.054      0
#2           1.370      1

hemhem=glm(hempresence~logarea, family=binomial(logit), subset=Hemybsm<2)
#This pulls out only the hemlocks from the full dataset and calculates the
#regression.
hemyb=glm(hempresence~logarea, family=binomial(logit), subset=Hemybsm==2)
#Same code, with only the birches from the full dataset.
hemsm=glm(hempresence~logarea, family=binomial(logit), subset=Hemybsm>2)

plot(logarea, hempresence, xlab = "Surface area of log (m2)",
ylab="Probability of hemlock seedling presence",
type="n", font.lab=2, cex.lab=1.5, axes=TRUE)
lines(logarea, predict(hemhem, logreg, "response"), lty=1, lwd=2)
lines(logarea, predict(hemyb, logreg, "response"), lty="dashed", lwd=2)
lines(logarea, predict(hemsm, logreg, "response"), lty="dotted", lwd=2)

```