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) :

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)...

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 to test), it gives me the wrong result (cp.r - tested separately
above - should not be significantly different between the two levels of
parasitaemia):

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



On Tue, Feb 2, 2010 at 2:03 AM, David Winsemius <dwinsemius@comcast.net>wrote:

>
> On Feb 1, 2010, at 4:10 PM, Amy Mikhail wrote:
>
>  Dear R epidemiologists,
>>
>> I have been trying to find the simplest possible way to:
>>
>> (a) Create contingency tables,
>>
>
> ?xtabs
>
>
>  (b) Perform a chi square or fisher exact test on those contingency tables,
>> and
>>
>
> ?chisq.test
> ?fisher.test
>
>
>
>  (c) Determine sensitivity, specificity and predictive values etc from a
>> rapid test compared to gold standard.
>>
>
> Those concepts are more typically used with a continuous test result such
> as hemoglobin or ALT that is predicting a "diagnosis". The ROC plotting
> facilities in the Epi package are quite good if that were the data
> situation.
>
>
>
>
>> More on my contingency table problem later, but for now problem (c):
>>
>> I tried to use the DiagnosisMed package, since by the description it
>> seemed
>> I could use my two variables (gold standard test results and results of
>> test
>> being evaluated) directly with the function (i.e. no need to make a 2x2
>> table first since the function would do this as well).
>>
>> I carefully coded my gold standard and test results as "positive" and
>> "negative", and removed all NAs.  I converted both columns from character
>> to
>> factors (which now had 2 levels).
>>
>> Then I tried this:
>>
>> diagnosis(ref, r1a)
>>
>
> No experience with that package.
>
>
>
>> where ref is my gold standard and r1a is my test being evaluated.
>>
>> I got this error:
>>
>> Error in uniroot(function(or) { :
>>  f() values at end points not of opposite sign
>>
>> I can't understand why - the data is as clean as a whistle.  Here is the
>> summary, fyi (six tests are being evaluated against one gold standard):
>>
>> summary(analc)
>>      ref            r1a            r1b            r2a
>> r2b            r3a            r3b
>> negative: 18   negative: 19   negative: 19   negative: 36   negative: 33
>> negative: 23   negative: 22
>> positive:202   positive:201   positive:201   positive:184   positive:187
>> positive:197   positive:198
>>
>> Did I misunderstand?  Does the diagnosis function require a 2x2 table as
>> input?
>>
>> Many thanks,
>> Amy
>>
> --
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>


-- 
Amy Mikhail
Program Manager, ACTc Afghanistan Malaria Project
London School of Hygiene & Tropical Medicine

****** NEW HPRO OFFICE ADDRESS
************************************************************************************************************************
HPRO Head Office, House number P860 (10th house on the right off Taimany
road), Street 10, Taimany, District 10, Kabul, Afghanistan
*********************************************************************************************************************************************************************

Email (Afg): amy.mikhail@googlemail.com
Email (UK): Amy.Mikhail@lshtm.ac.uk
Tel (Afg): +93 (0)706 126627
Tel (UK): +44 (0)781 4176107

	[[alternative HTML version deleted]]

