0

I have a dataset where I am training on to coerce as dataset (foundable in the onòy in SetMethods package)

library(QCA)
library(SetMethods)

data(SCHF)

# Get the truth table for the presence of the outcome:

TT_y <- truthTable(SCHF, outcome = "EXPORT",
                   conditions = c("EMP","BARGAIN","UNI","OCCUP","STOCK", "MA"),
                   incl.cut = .9,
                   complete = TRUE,
                   PRI = TRUE,
                   sort.by = c("out", "incl", "n"))

what I would like to to is to coerce this object into a dataset. This is my failing trial

table = as.data.table(TT_y)
table

Would you have some possible alternative? Thanks

harre
  • 7,081
  • 2
  • 16
  • 28
12666727b9
  • 1,133
  • 1
  • 8
  • 22
  • Please post the output from `dput(TT_y)` to your question. [Or `dput(head(TT_y))` if the first output is large. ] – Limey Mar 05 '23 at 10:56

1 Answers1

1

We could extract the tt data frame directly from the object returned by truthTable. We will, however, need to remove the rows where n == 0 to obtain what you're after.

library(QCA)

tT <- truthTable(LC, "SURV")$tt # Extract data frame from object

tT[tT$n > 0, ] # Show the relevant rows

Output:

   DEV URB LIT IND STB OUT n incl PRI       cases
1    0   0   0   0   0   0 3    0   0    GR,PT,ES
2    0   0   0   0   1   0 2    0   0       IT,RO
5    0   0   1   0   0   0 2    0   0       HU,PL
6    0   0   1   0   1   0 1    0   0          EE
22   1   0   1   0   1   1 2    1   1       FI,IE
23   1   0   1   1   0   0 1    0   0          AU
24   1   0   1   1   1   1 2    1   1       FR,SE
31   1   1   1   1   0   0 1    0   0          DE
32   1   1   1   1   1   1 4    1   1 BE,CZ,NL,UK

Data:

The data used here is the Lipset binary crisp data used in the first example in the documentation of QCA::truthTable. I cannot find the SCHF-dataset.


Update: I've found the dataset (and updated OP). Same approach, new filtering :-)

library(SetMethods)
library(QCA)

data(SCHF)

tT <- TT_y$tt
tT[order(tT$incl, decreasing = TRUE), 1:10]

Output:

   EMP BARGAIN UNI OCCUP STOCK MA OUT  n              incl                PRI
19   0       1   0     0     1  0   1  1 0.981958762886598  0.911392405063291
28   0       1   1     0     1  1   1  2 0.965765765765766  0.898666666666667
16   0       0   1     1     1  1   1  1 0.963696369636964  0.865853658536585
43   1       0   1     0     1  0   1  4 0.950653120464441  0.875457875457875
63   1       1   1     1     1  0   1  2 0.941176470588236  0.755000000000001
64   1       1   1     1     1  1   1  7 0.940740740740741  0.859649122807018
27   0       1   1     0     1  0   1  1 0.930354796320631  0.713513513513514
8    0       0   0     1     1  1   1  3 0.930348258706468              0.776
60   1       1   1     0     1  1   1  4 0.928881179531657  0.796019900497512
11   0       0   1     0     1  0   1  6   0.9201244813278  0.849019607843137
32   0       1   1     1     1  1   1  4 0.910460992907802  0.764568764568765
29   0       1   1     1     0  0   1  1   0.9004329004329  0.333333333333332
56   1       1   0     1     1  1   0  5 0.894366197183099  0.652777777777778
62   1       1   1     1     0  1   0  1  0.88268156424581  0.267441860465115
12   0       0   1     0     1  1   0 10 0.879601226993865  0.789261744966443
61   1       1   1     1     0  0   0  2           0.84375  0.227642276422765
55   1       1   0     1     1  0   0  2   0.8348623853211  0.296874999999999
57   1       1   1     0     0  0   0  1 0.823931623931624  0.213740458015268
2    0       0   0     0     0  1   0  1  0.78688524590164   0.31578947368421
49   1       1   0     0     0  0   0  4 0.742339832869081  0.114832535885168
10   0       0   1     0     0  1   0  2 0.661538461538462  0.158469945355191
53   1       1   0     1     0  0   0 12 0.606844741235392 0.0907335907335905
1    0       0   0     0     0  0   ?  0                 -                  -
3    0       0   0     0     1  0   ?  0                 -                  -
4    0       0   0     0     1  1   ?  0                 -                  -
5    0       0   0     1     0  0   ?  0                 -                  -
6    0       0   0     1     0  1   ?  0                 -                  -
7    0       0   0     1     1  0   ?  0                 -                  -
9    0       0   1     0     0  0   ?  0                 -                  -
13   0       0   1     1     0  0   ?  0                 -                  -
14   0       0   1     1     0  1   ?  0                 -                  -
15   0       0   1     1     1  0   ?  0                 -                  -
17   0       1   0     0     0  0   ?  0                 -                  -
18   0       1   0     0     0  1   ?  0                 -                  -
20   0       1   0     0     1  1   ?  0                 -                  -
21   0       1   0     1     0  0   ?  0                 -                  -
22   0       1   0     1     0  1   ?  0                 -                  -
23   0       1   0     1     1  0   ?  0                 -                  -
24   0       1   0     1     1  1   ?  0                 -                  -
25   0       1   1     0     0  0   ?  0                 -                  -
26   0       1   1     0     0  1   ?  0                 -                  -
30   0       1   1     1     0  1   ?  0                 -                  -
31   0       1   1     1     1  0   ?  0                 -                  -
33   1       0   0     0     0  0   ?  0                 -                  -
34   1       0   0     0     0  1   ?  0                 -                  -
35   1       0   0     0     1  0   ?  0                 -                  -
36   1       0   0     0     1  1   ?  0                 -                  -
37   1       0   0     1     0  0   ?  0                 -                  -
38   1       0   0     1     0  1   ?  0                 -                  -
39   1       0   0     1     1  0   ?  0                 -                  -
40   1       0   0     1     1  1   ?  0                 -                  -
41   1       0   1     0     0  0   ?  0                 -                  -
42   1       0   1     0     0  1   ?  0                 -                  -
44   1       0   1     0     1  1   ?  0                 -                  -
45   1       0   1     1     0  0   ?  0                 -                  -
46   1       0   1     1     0  1   ?  0                 -                  -
47   1       0   1     1     1  0   ?  0                 -                  -
48   1       0   1     1     1  1   ?  0                 -                  -
50   1       1   0     0     0  1   ?  0                 -                  -
51   1       1   0     0     1  0   ?  0                 -                  -
52   1       1   0     0     1  1   ?  0                 -                  -
54   1       1   0     1     0  1   ?  0                 -                  -
58   1       1   1     0     0  1   ?  0                 -                  -
59   1       1   1     0     1  0   ?  0                 -                  -
harre
  • 7,081
  • 2
  • 16
  • 28