-2

data is fraway boot

I want to

Make a plot showing age- x axis and proportion of Down’s births in
each age-group -y axis. Add two curves showing the predicted probabilities
from the main effects model and the quadratic model. with legend.

lmod2 <- glm(prop ~ age + I(age^2),
             family=quasibinomial, finaldata)
lmod <- glm(prop ~ age,
            family=quasibinomial, finaldata)

things I tried:

plot(predict(lmod,lmod2, newdata = list(age = 16:50), type = 'response'), type = 'l',
+      ylab = "Probability of Down's syndrome per live birth", 
+      xlab = 'Maternal age')
Error in !se.fit : invalid argument type


> plot(lmod,lmod2)
Error in plot.lm(lmod, lmod2) : 'which' must be in 1:6

please guide me.

  • plot() will generate multiple plots (res vs fitted, Q-Q, etc.). Is there any specific plot you want out of your glm() models or will any plot be adequate? – jrcalabrese Feb 12 '23 at 20:20
  • @jrcalabrese thanks for the guidence though they want the two curve in one plot with legend could you please guide? – fashionable Feb 12 '23 at 20:26
  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 12 '23 at 20:38
  • @jrcalabrese thanks. I had another question how can we fit a model HG as the response and the 3 covariates as main effects? Would this be the right way? m1 <- glm(cbind(HG,PI-HG)~ EH + NV, family = binomial, data = detectseparation::endometrial) – fashionable Feb 12 '23 at 21:17
  • @jrcalabrese my limit has been done :( – fashionable Feb 12 '23 at 21:23
  • You can only include [one question per post](https://meta.stackexchange.com/a/222741/1285412). When you are able to post again, please make sure your post is [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). With my answer, I had to use `data(mtcars)` because you didn't provide `dput(finaldata)`. – jrcalabrese Feb 12 '23 at 21:28

1 Answers1

0

You can use par and mfrow to set the layout of what you want your plots to look like.

data(mtcars)
lmod <- glm(vs ~ mpg, family = quasibinomial, mtcars)
lmod2 <- glm(vs ~ mpg + I(mpg^2), family = quasibinomial, mtcars)

par(mfrow=c(1, 2))
# or par(mfrow=c(2, 1))
plot(predict(lmod, type = 'response'), type = 'l',
     ylab = "Probability of Down's syndrome per live birth", 
     xlab = 'Maternal age')
plot(predict(lmod2, type = 'response'), type = 'l',
     ylab = "Probability of Down's syndrome per live birth", 
     xlab = 'Maternal age')

enter image description here

If you would like both lines to be plotted on the same plot, you can change the second plot() to lines(). Just make sure to assign a different color.

data(mtcars)
lmod <- glm(vs ~ mpg, family = quasibinomial, mtcars)
lmod2 <- glm(vs ~ mpg + I(mpg^2), family = quasibinomial, mtcars)

par(mfrow=c(1,1))
plot(predict(lmod, type = 'response'), type = 'l', 
     col = "red",
     ylab = "Probability of Down's syndrome per live birth",  
     xlab = 'Maternal age')

lines(predict(lmod2, type = 'response'), type = 'l',
      col = "blue",
      ylab = "Probability of Down's syndrome per live birth", 
      xlab = 'Maternal age')

enter image description here

jrcalabrese
  • 2,184
  • 3
  • 10
  • 30