Luvpsi
Luvpsi

Reputation:

How do I fit a GLM using Binomial Distribution for this data in R?

I have been asked to fit a GLM using binomial distribution for the following question:

A survey was conducted to evaluate the effectiveness of a new canine Cough vaccine that had been administered in a local community. For marketing purpose, the vaccine was provided free of charge in a two-shot sequence over a period of two weeks to those who were wishing to bring their dogs to avail of it. Some dogs received the two-shot sequence, some appeared only for the first shot, and others received neither. A survey of 600 local dog owners in the following session provided the information shown in the table below. enter image description here

How do I get the data into R in order to get the correct format to fit a GLM for binomial dist?

Any help would be great!

Upvotes: 2

Views: 338

Answers (1)

Glen_b
Glen_b

Reputation: 8252

One suitable way would be:

vaccine <- c(rep(c(0,1,2),c(12,4,8)),rep(c(0,1,2),c(175,61,340)))
cough <- c(rep(1,12+4+8),rep(0,175+61+340))

Then you could do something like:

linfit <- glm(cough~vaccine,family=binomial)
summary(linfit)

or

factorfit <- glm(cough~as.factor(vaccine),family=binomial)
summary(factorfit)

or

ordfactorfit <- glm(cough~ordered(vaccine),family=binomial)
summary(ordfactorfit)

or perhaps some other possibilities, depending on what your particular hypotheses were.

This isn't the only way to do it (and you may not want to do it with really large data sets), but "untabulating" in this fashion makes some things easy. You can retabulate easily enough (table(data.frame(cough=cough,vaccine=vaccine))).

You may also find the signed-root-contributions-to-chi-square interesting:

 t=table(data.frame(cough=cough,vaccine=vaccine))
 r=rowSums(t)
 c=colSums(t)
 ex=outer(r,c)/sum(t)
 print((t-ex)/sqrt(ex),d=3)
     vaccine
cough      0      1      2
    0 -0.337 -0.177  0.324
    1  1.653  0.868 -1.587

These have an interpretation somewhat analogous to standardized residuals.

A plot of the proportion of Nos against vaccine (with say $\pm$1 standard errors marked in) would be similarly useful.

Upvotes: 3

Related Questions