简体   繁体   中英

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. 在此处输入图片说明

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!

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 No s against vaccine (with say $\\pm$1 standard errors marked in) would be similarly useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM