I have the following data format:

id     drug_type     result
--     ---------     ------
1      A             Yes
2      B             No
3      A             No
4      Placebo       Yes

How do I test the result column for significance of each drug_type that is not Placebo, against the Placebo. Usually I would take subsets of the table based on drug_type and do:


however I know I should not be using a t-test for categorical data. The prop.test handles categorical variables, but to me does not seem to be able to compare each non-Placebo drug group to the placebo, but merely run significance test on the proportion of successful tests within each drug_type.

any suggestions?

  • $\begingroup$ You can run Fisher's exact test for each treatment vs placebo. The results will (almost) match the one from the suggested logistic regression. $\endgroup$
    – Michael M
    Jul 27, 2015 at 17:54

2 Answers 2


How about logistic regression -- especially if you have other factors that you need to control? You can simply set up a contrast to test differences in drug types.

For example:

id<-seq(1, 100)
drug_type<-as.factor(sample(c(LETTERS[1:2], "Placebo"), size=100, replace=TRUE))
result<-as.factor(sample(c("Yes","No"), size=100, replace=TRUE))
mydf<-data.frame(id, drug_type, result)
mydf2<-cbind(mydf, result2=as.numeric(mydf$result)-1)

mymodel<-glm(result2~drug_type, data=mydf2, family="binomial")

L<-cbind(0, 1, -1)
#For example to test Test Drug B against Placebo
wald.test(b = coef(mymodel), Sigma = vcov(mymodel), L = L)
  • $\begingroup$ thank you @StatsStudent - this is suitable for my analysis. would you be able to explain where in the wald.test does it pick out drug B being tested against Placebo? I can seem to pick out how drug A is not used for example. $\endgroup$ Jul 28, 2015 at 10:02
  • $\begingroup$ In the statement right before wald.test, I create a vector L, which sets up the contrast. It sets the intercept term to 0 since the intercept term drops out when subtracting the Drug B effect from the Placebo effect. The next 1 is setting the coefficient for Drug B to +1 and the -1 is setting the coefficient of the Placebo to -1 so you obtain $\hat\beta_{B}-\hat\beta_{placebo}$ which measures the mean difference between the two treatments. So it does pick out drug B being tested against the Placebo. I'm not sure what you mean by "I can seem to pick out how drug A is not used for example." $\endgroup$ Jul 28, 2015 at 14:29
  • $\begingroup$ To be more precise, I should have said that $\hat\beta_{B}-\hat\beta_{placebo}$ is the $estimated$ mean difference between the two treatments. $\endgroup$ Jul 28, 2015 at 14:42
  • $\begingroup$ thanks @StatsStudent. I think what I am getting at is when you say The next 1 is setting the coefficient for Drug B to +1, to me I see no way in the code of how the second parameter of L =1 relates to drugB. I assume that each parameter of the vector L represents each ordered unique drug type. For example if I had drugs A,B,C,D....placebo then L would look like L = c(drugA,drugB,drugC,drugD,......placebo). Have I interperated this correctly? $\endgroup$ Jul 28, 2015 at 15:56
  • $\begingroup$ No, but, it depends on how you parametrized your model. In the example I have used, I used the default R parameterization, which sets the first ordered level to 0 (in this case drug A). If you run a model.matrix on the model (in my example head(model.matrix(mymodel)), you will see that the the estimated coefficients are, in order, (Intercept), drug_typeB and finally drug_typePlacebo. The contrast vector corresponds to this parameterization. $\endgroup$ Jul 28, 2015 at 16:14

I think a Chi-square test would be appropriate for your situation, provided that you have in each cell more than 5 observations (i.e., in your case ID's). What you need to do is make a 2 x 2 contingency table of drug type (A vs B) and Result (Yes vs No) and count the occurrences in each cell. You can than test if there is an association between the two variables. See for examples of medical research the following link: http://ocw.jhsph.edu/courses/fundepiii/pdfs/lecture17.pdf

In R the function chisq.test(table) can be used.

  • 3
    $\begingroup$ This doesn't address @brucezeppelin 's question about comparing the two drugs to his placebo condiion. A Chi square statistic could work, but not in the 2x2 contingecy table as you have suggested here. $\endgroup$
    – user32490
    Jul 27, 2015 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.