On Feb 1, 2010, at 5:01 PM, Amy Mikhail wrote: > Dear David, > > Many thanks for your reply. My rapid test results are categorical > (positive negative) and I have converted them to factors. My gold > standard (parasitaemia on a blood slide) is a continuous numerical > variable but can be categorical too. > > I tried xtabs, but it doesn't seem to like the use of formulas with > my input (cp.r is factoral, r2.vc is continuous numerical) : >
I did not suggest using xtabs with a continuous variable. > ref <- ftable(xtabs(cp.r ~ r2.vc, data = res)) > > Error in Summary.factor(c(2L, 3L, 2L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, > 2L, : > sum not meaningful for factors > > I have tried chisq.test and fisher.test too, they work fine but the > input is somewhat more laborious than I would like - I was hoping > there might be a wrapper function that would do two things (a) > create a 2x2 table and (b) then do fisher or chi square on it (so > that the input are the actual variables)... > set.seed(7) > Paralev<- sample(c("Low", "High"), 250, replace=TRUE) > Result <- sample(c("False neg", "True Pos"), 250, prob=c(1/250, 249/250), replace=TRUE) > xtabs(data=cbind(Paralev, Result)) Result Paralev False neg True Pos High 1 126 Low 0 123 > fisher.test( xtabs(data=cbind(Paralev, Result)) ) Fisher's Exact Test for Count Data data: xtabs(data = cbind(Paralev, Result)) p-value = 1 alternative hypothesis: true odds ratio is not equal to 1 95 percent confidence interval: 0.02483 Inf sample estimates: odds ratio Inf > > If I create a matrix and then do fisher's on it, the result is as I > expect: > > > ParaSens <- matrix(c(1,0,124,130), nrow = 2, dimnames = > list(Paralev = c("Low", "High"), Result = c("False negative", "True > positive"))) > > ParaSens > Result > Paralev False negative True positive > Low 1 124 > High 0 130 > > fisher.test(ParaSens, alternative = "greater") > > Fisher's Exact Test for Count Data > > data: ParaSens > p-value = 0.4902 > alternative hypothesis: true odds ratio is greater than 1 > 95 percent confidence interval: > 0.05473174 Inf > sample estimates: > odds ratio > Inf > > > If I try to use the stacktable function in epicalc, however (because > I have 6 rdts What is a "rdts"? > to test), it gives me the wrong result (cp.r - tested separately > above - should not be significantly different between the two levels > of parasitaemia): This is gobbleygook to me. Consider providing dput(<a name of an R object>) > > tableStack(vars=6:11, by=paralev) > negative < 5,000 T/uL > 5,000 T/uL Test > stat. P value > cp.r Fisher's exact test > < 0.001 > Invalid 1 (3.7) 6 (4.6) 4 (3) > Negative 22 (81.5) 1 (0.8) 0 (0) > Pv 4 (14.8) 124 (94.7) 130 (97) > > cp.c Fisher's exact test > < 0.001 > Invalid 1 (3.7) 3 (2.3) 2 (1.5) > Negative 22 (81.5) 1 (0.8) 0 (0) > Pv 4 (14.8) 127 (96.9) 132 (98.5) > > cv.r Fisher's exact test > < 0.001 > Invalid 0 (0) 3 (2.3) 1 (0.7) > Negative 23 (85.2) 19 (14.5) 1 (0.7) > Pv 4 (14.8) 109 (83.2) 132 (98.5) > > cv.c Fisher's exact test > < 0.001 > Invalid 0 (0) 3 (2.3) 3 (2.2) > Negative 23 (85.2) 18 (13.7) 1 (0.7) > Pv 4 (14.8) 110 (84) 130 (97) > > sv.r Fisher's exact test > < 0.001 > Invalid 5 (18.5) 14 (10.7) 31 (23.1) > Mixed 0 (0) 0 (0) 1 (0.7) > Negative 22 (81.5) 7 (5.3) 0 (0) > Pv 0 (0) 110 (84) 102 (76.1) > > sv.c Fisher's exact test > < 0.001 > Invalid 4 (14.8) 8 (6.1) 19 (14.2) > Negative 20 (74.1) 5 (3.8) 0 (0) > Pv 3 (11.1) 118 (90.1) 115 (85.8) > > Please note that in tableStack I have a third (unwanted) factor > level (Invalid): maybe this is what is causing the problem, since > the above is a 3x2 table wherease when I create a matrix separately > I leave out the invalids so that it is only a 2x2 table? > > Regarding your comment on continuous variables - had not really come > across that one before, for malaria rapid diagnostic tests (which I > am dealing with) the sensitivity and specificity is always reported > with reference to either microscopy results or PCR results as the > gold standard. PPV has some value too in that it can take into > account invalid RDT results, wherease the other two measurements > can't. > > Best, > Amy > > snipped earlier material. David Winsemius, MD Heritage Laboratories West Hartford, CT [[alternative HTML version deleted]] _______________________________________________ R-sig-Epi@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-epi