dtkaplan / statisticalModeling

Other
11 stars 17 forks source link

Trouble with gmodel, removing line and adding confidence intervals #32

Open GabriellaS-K opened 3 years ago

GabriellaS-K commented 3 years ago

Hi,

I am trying to use gmodel to visualise a glm: mymodel <-glm(formula=prob~city+z.age+married, data=census ,family = "binomial") prob is probability of children where city is 3 groups, 1, 2 or 3 z.age is z.scored age married is yes/no

Currently gmodel gives an output of two panes, one for married = yes, the other married = no. With probability on y and city group on x.

Screenshot 2021-02-22 at 18 48 52

I need to change a few things on this graph, but am not sure how.

  1. the title of both graph panes, currently looks like 'married:FALSE and married:TRUE', is there a way to rename this?
  2. The data points should not be joined, as the city variable is a factor
  3. How to add confidence intervals? Each time I try, I get an error.

Currently my model script is trying to remove the lines that join the data by removing a layer:

mymodelgraph <- gmodel(mymodel)+
  ggplot2::ylab("Probability") +
  ggplot2:: aes(colour=z.age) + 
  scale_colour_manual(values = my_colorsvibrant)
mymodelgraph $layers[[2]] <- NULL 
mymodelgraph

If I add confidence intervals:

mymodelgraph <- gmodel(mymodel,  intervals = "confidence")+
  ggplot2::ylab("Probability") +
  ggplot2:: aes(colour=z.age) + 
  scale_colour_manual(values = my_colorsvibrant)
mymodelgraph $layers[[2]] <- NULL 

I get a warning and error:

Warning messages:
1: Ignoring unknown aesthetics: linetype 
2: Ignoring unknown aesthetics: fill 
Error in FUN(X[[i]], ...) : object 'upr' not found

I would be very grateful for any help!

Thank you :)