This question is related to a question I had in R on SO here
The background of my question is fairly simple. I was given two "databases" in the form of data.frames
that each contain about 100 patients each from two different hospitals. Each patient received multiple different antibiotics during the course of their treatment. I now wanted to calculcate all of the different classes of antibiotics given and then compare whether antibiotic "xyz" was given more frequently in hospital 1 versus hospital 2 (or vice a versa; two-tailed).
Now a bit of a catch is that the documentation in hospital 1 is better than in hospital 2, so ideally, you'd want to compare proportions of the total number of antibiotics (given/documented) and not "raw counts" in an attempt to "correct" for this difference in accuracy of the two databases.
So I thought I'd have to summarize my data in contingency tables and then run a chisq.test
on it, but the way the data is summarized below, makes me think I need to run a wilcox.test
.
May I ask of you experts here if
- any of you have had to deal with this kind of issue before and
- what you suggest is the best way of dealing with it?
Below you can find selected columns of the interim-summary of the respective data.frames
. Hospital 1 is hosp1
, hospital 2 is hosp2
. The data can be pulled from the link provided above
>hosp1 ### this is the summary of hospital 1
id total perc
1 1st gen Cephalosporin 6 1.9
2 3rd gen Cephalosporin 65 20.5
3 4th gen Cephalosporin 10 3.2
4 Aminoglycoside 31 9.8
5 Glycopeptide 55 17.4
6 Lincosamide 2 0.6
7 Macrolide 3 0.9
8 Penicillin 36 11.4
9 Tetracycline 2 0.6
10 Trimethoprim 2 0.6
11 Ureidopenicillin 46 14.5
12 Carbapenem 19 6.0
13 Fluoroquinolone 17 5.4
14 Nitroimidazole 12 3.8
15 Antifungal 6 1.9
16 Oxazolidinone 2 0.6
17 Rifamycin 1 0.3
18 Polypeptide 1 0.3
19 Lipopeptide 1 0.3
> hosp2 ### this is the summary of hosp2
id total perc
1 3rd gen Cephalosporin 19 9.4
2 Carbapenem 37 18.2
3 Fluoroquinolone 24 11.8
4 Glycopeptide 32 15.8
5 Penicillin 29 14.3
6 Ureidopenicillin 36 17.7
7 Lipopeptide 4 2.0
8 Macrolide 2 1.0
9 Aminoglycoside 9 4.4
10 Polypeptide 1 0.5
11 Rifamycin 1 0.5
12 Tetracycline 1 0.5
13 Lincosamide 1 0.5
14 Quinolone 2 1.0
15 Sulfonamide 2 1.0
16 Nitroimidazole 1 0.5
17 Polymyxine 1 0.5
18 Colistin 1 0.5
Perhaps the merged data makes more sense as to what I'm aiming to compare:
new_df2 <- merge(hosp1, hosp2, by=id, all=TRUE)
id total.x perc.x total.y perc.y
1 1st gen Cephalosporin 6 1.9 NA NA
2 3rd gen Cephalosporin 65 20.5 19 9.4
3 4th gen Cephalosporin 10 3.2 NA NA
4 Aminoglycoside 31 9.8 9 4.4
5 Glycopeptide 55 17.4 32 15.8
6 Lincosamide 2 0.6 1 0.5
7 Macrolide 3 0.9 2 1.0
8 Penicillin 36 11.4 29 14.3
9 Tetracycline 2 0.6 1 0.5
10 Trimethoprim 2 0.6 NA NA
11 Ureidopenicillin 46 14.5 36 17.7
12 Carbapenem 19 6.0 37 18.2
13 Fluoroquinolone 17 5.4 24 11.8
14 Nitroimidazole 12 3.8 1 0.5
15 Antifungal 6 1.9 NA NA
16 Oxazolidinone 2 0.6 NA NA
17 Rifamycin 1 0.3 1 0.5
18 Polypeptide 1 0.3 1 0.5
19 Lipopeptide 1 0.3 NA NA
20 Lipopeptide NA NA 4 2.0
21 Quinolone NA NA 2 1.0
22 Sulfonamide NA NA 2 1.0
23 Polymyxine NA NA 1 0.5
24 Colistin NA NA 1 0.5
And then basically run something like:
with(new_df2(chisq.test(total.x[id=="1st gen Cephaolosporin], total.y[id=="1st gen Cephaolosporin])
Would the wilcox.test()
only apply if I were comparing total counts along the whole column? I'm just getting a bit confused here, because effectively the number in the columns total.x
and total.y
represent counts and for some reason I'm now thinking of a wilcoxon test...but it's all based on categorical data.
Thus, making a contingency table out of this would actually require you to reformat the table into something along the lines of this (to perform for example a comparison of "3rd generation Cephalosporins")
thirdgenhosp1 <- rep(c("Yes", "No"), times=c(65, (sum(new.df2$total.x)-65)))
thirdgenhosp2 <- rep(c("Yes", "No"), times=c(19, (sum(new.df2$total.y)-19)))
### combine the two and try to "correct" for the difference in accuracy of documentation
thirdgen_all <- cbind(thirdgenhosp1,
c(thirdgenhosp2, rep(NA, length(thirdgenhosp1)-length(thirdgenhosp2))))
### then make a data.frame out of this to be able to analyse it
thirdgen_all_df <- data.frame(thirdgen_all)
names(thirdgen_all_df)[2] <- "thirdgenhosp2"
# then perform the comparison
with(thirdgen_all_df, chisq.test(thirdgenhosp1, thirdgenhosp2, correct=F))
Would there be a more efficient way of doing this? And am I actually doing the right thing?
Thanks for any help whatsoever. This has now been bountied :).
id
represents the name of the antibiotic. The columntotal
represents the number of times it was given (or counted that it was given) and theperc
column indicates the percentagetotal
represents of the sum of thetotal
column. The columnsAB1
toABn
were the original headings of a table in long-format, which contained the variables encoded in theid
column and can thus be disregarded for this question. Thx for any thoughts you may have. $\endgroup$