简体   繁体   English

如何在R中使用此数据使用二项分布来拟合GLM?

[英]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: 我被要求使用二项分布来拟合GLM,以解决以下问题:

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. 在接下来的会议中对600名当地狗主人进行的调查提供了下表中显示的信息。 在此处输入图片说明

How do I get the data into R in order to get the correct format to fit a GLM for binomial dist? 我如何将数据输入R以获取正确的格式以适合二项式dist的GLM?

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)) ). 您可以轻松地table(data.frame(cough=cough,vaccine=vaccine))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. 比例的曲线No对阵疫苗(有说$ \\ $下午在标记1个标准误差)将同样有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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