Home > Enterprise >  Creating and plotting a Binomial GLM
Creating and plotting a Binomial GLM

Time:05-31

I am trying to create a Binomial GLM with a logistic link to model my data. The variables are: age (age group; 25-29, 30-39 or 40-49), education (educational level; high or low), wantsMore (may want more children in longer term; yes or no), using (number of women using contraception) and notUsing (number of women not using contraception).

I am trying to predict the number of numbers of women not using contraception using the education, age and wantsMore variables.

I have set up my model as seen below but I cant get it to work due to error messages, also shown below. Does anyone know where I have gone wrong in setting up the model?

my model

my_model = glm(cbind(notUsing, using-notUsing) ~ age   education   wantsMore,
      data = contraceptive2,
      family = binomial(link = "logit"))

error message

Error in family$linkfun(mustart) : Value 7.64286 out of range (0, 1)

Assume this is linked to my explanatory variables but unsure how to change it

My dataframe

    head(contraceptive2)
    age education wantsMore notUsing using
1   <25       low       yes       53     6
2   <25       low        no       10     4
3   <25      high       yes      200    52
4   <25      high        no       50    10
5 25-29       low       yes       60    14
6 25-29       low        no       19    10

CodePudding user response:

The two column matrix in the left hand side of the formula should contain "successes" and "failures", i.e. in this case "notUsing" and "using" (or vice-versa). You don't want to subtract the successes from the failures. Apart from anything this data would have a negative number of failures! Try:

my_model = glm(cbind(notUsing, using) ~ age   education   wantsMore,
  data = contraceptive2,
  family = binomial(link = "logit"))
  • Related