user1477388
user1477388

Reputation: 21430

Unexpected output from CrossTable

I am using the CrossTable method from the gmodels package in the following code:

CrossTable(news_test_pred, news_raw_test$type, prop.chisq = F, prop.c = F, prop.t = F, dnn = c('predicted', 'actual'))

Upon executing, the output is this:

Total Observations in Table:  19 


             | actual 
   predicted |  negative |  positive | Row Total | 
-------------|-----------|-----------|-----------|
    negative |         3 |         0 |         3 | 
             |     1.000 |     0.000 |     0.158 | 
-------------|-----------|-----------|-----------|
    positive |         9 |         7 |        16 | 
             |     0.562 |     0.438 |     0.842 | 
-------------|-----------|-----------|-----------|
Column Total |        12 |         7 |        19 | 
-------------|-----------|-----------|-----------|

My question is, if there were 12 "actual negatives" and, of which, I predicted only 3 of them correctly, why does it show 100%?

Am I not reading this cross table correctly?

Upvotes: 0

Views: 100

Answers (1)

MrFlick
MrFlick

Reputation: 206197

The probabilities listed below the counts in the inner cells represent a row probability

 1.00+0.00 == 1
 0.562+0.438 == 1

This is saying that for the 3 values you predicted to be negative, all of them were actually negative.

However it sounds like you want to condition on the true value rather than the prdicted value. The easiest way it just to swap your parameters to CrossTable

CrossTable(news_raw_test$type, news_test_pred, 
    prop.chisq = F, prop.c = F, prop.t = F, 
    dnn = c('actual', 'predicted'))

Upvotes: 1

Related Questions