Search code examples
rplotlogistic-regression

Plot of observed values vs fitted values


I want to plot the observed X's vs observed and fitted Y's. Here is my code:

conc <- c(1.6907, 1.7242, 1.7552, 1.7842, 1.8113, 1.8369, 1.8610,1.8839)
number <- c(59,60,62,56,63,59,62,60)
dead <- c(6,13,18,28,52,53,61,60)
y <- dead/number

minimal.model <- glm(y ~1, family = binomial(link=logit), weights=number)
plot(conc, minimal.model$fitted)
points(conc,y,pch=4)

This is what I need to get

enter image description here

and this is what I get

enter image description here

Note that some of observed Y's are missing. What am I doing wrong?


Solution

  • I don't know what's going on with the x-axis labels: you might want to try opening a new graphics window.

    For the points, you need to set the y-axis range appropriately

    par(las=1,bty="l") ## cosmetic
    plot(conc, minimal.model$fitted,ylim=c(0,1))
    points(conc,y,pch=4)
    

    Alternately you could use matplot() to plot both at once:

    matplot(conc,cbind(minimal.model$fitted,y),
            col=1,pch=c(1,4),ylab="y")