Examples

Simple contingency table

using MetidaFreq, CSV, DataFrames;

df = CSV.File(joinpath(dirname(pathof(MetidaFreq)), "..", "test", "csv",  "ft.csv")) |> DataFrame

ct = MetidaFreq.contab(df, :row, :col)
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c   20   24      44
  d   83   44     127
 --- ---- ---- -------

Confidence Intervals

MetidaFreq.propci(ct, method = :cp)
2-element Vector{Tuple{Float64, Float64}}:
 (0.3039071135156737, 0.6115278775270854)
 (0.5640069557739404, 0.7357376131143176)
MetidaFreq.diffci(ct)
(-0.36019484734063234, -0.029845370337608354)
MetidaFreq.orci(ct)
(0.2208465177513969, 0.8835988210482012)
MetidaFreq.rrci(ct)
(0.47558217064492814, 0.951044895777462)

Sorting example

ct = MetidaFreq.contab(df, :row, :col; sort = :s1)
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c    0    2       2
  d   65   34      99
 --- ---- ---- -------
  ID: s1 => f; 
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c   20   22      42
  d   18   10      28
 --- ---- ---- -------
  ID: s1 => e; 
ct = MetidaFreq.contab(df, :row, :col; sort = [:s1, :s2])
  Contingency table:
 --- --- ---- -------
      b    a   Total 
 --- --- ---- -------
  c   0    0       0
  d   3   10      13
 --- --- ---- -------
  ID: s1 => f; s2 => g; 
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c   14   10      24
  d    0    0       0
 --- ---- ---- -------
  ID: s1 => e; s2 => g; 
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c    0    0       0
  d   41   20      61
 --- ---- ---- -------
  ID: s1 => f; s2 => h; 
  Contingency table:
 --- --- --- -------
      b   a   Total 
 --- --- --- -------
  c   0   0       0
  d   0   0       0
 --- --- --- -------
  ID: s1 => e; s2 => h; 
  Contingency table:
 --- ---- --- -------
       b   a   Total 
 --- ---- --- -------
  c    0   2       2
  d   21   4      25
 --- ---- --- -------
  ID: s1 => f; s2 => i; 
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c    6   12      18
  d   18   10      28
 --- ---- ---- -------
  ID: s1 => e; s2 => i; 
MetidaFreq.dropzeros!(ct)
  Contingency table:
 --- --- ---- -------
      b    a   Total 
 --- --- ---- -------
  c   0    0       0
  d   3   10      13
 --- --- ---- -------
  ID: s1 => f; s2 => g; 
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c   14   10      24
  d    0    0       0
 --- ---- ---- -------
  ID: s1 => e; s2 => g; 
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c    0    0       0
  d   41   20      61
 --- ---- ---- -------
  ID: s1 => f; s2 => h; 
  Contingency table:
 --- ---- --- -------
       b   a   Total 
 --- ---- --- -------
  c    0   2       2
  d   21   4      25
 --- ---- --- -------
  ID: s1 => f; s2 => i; 
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c    6   12      18
  d   18   10      28
 --- ---- ---- -------
  ID: s1 => e; s2 => i; 
MetidaFreq.dropzeros!(ct)
  Contingency table:
 --- --- ---- -------
      b    a   Total 
 --- --- ---- -------
  c   0    0       0
  d   3   10      13
 --- --- ---- -------
  ID: s1 => f; s2 => g; 
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c   14   10      24
  d    0    0       0
 --- ---- ---- -------
  ID: s1 => e; s2 => g; 
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c    0    0       0
  d   41   20      61
 --- ---- ---- -------
  ID: s1 => f; s2 => h; 
  Contingency table:
 --- ---- --- -------
       b   a   Total 
 --- ---- --- -------
  c    0   2       2
  d   21   4      25
 --- ---- --- -------
  ID: s1 => f; s2 => i; 
  Contingency table:
 --- ---- ---- -------
       b    a   Total 
 --- ---- ---- -------
  c    6   12      18
  d   18   10      28
 --- ---- ---- -------
  ID: s1 => e; s2 => i; 

Meta-analysis

pf1 = MetidaFreq.contab([15 8; 5 14])
pf2 = MetidaFreq.contab([45 72; 23 95])
mds = MetidaFreq.DataSet([pf1, pf2])
  Contingency table:
 --- ---- ---- -------
                Total 
 --- ---- ---- -------
      15    8      23
       5   14      19
 --- ---- ---- -------

  Contingency table:
 --- ---- ---- -------
                Total 
 --- ---- ---- -------
      45   72     117
      23   95     118
 --- ---- ---- -------

mp = MetidaFreq.metaprop(mds, :rr)
  Meta-proportion:
  Tables: 2
  Metric: rr
  Metric vector: [0.9075570519054006, 0.6796789635090787]
  Metric variance: [0.17055682684973306, 0.04867889827359245]
mpf = MetidaFreq.metapropfixed(mp; weights = :mh)
  Meta-proportion fixed-effect result:
  Weights (%): [19.297, 80.703]
  Estimate: 0.727886
  Variance (Std. error): 0.0378135 (0.194457)
  Exp(Estimate): 2.0707
  Chi²: 14.3193
  Q: 0.237012
mpf = MetidaFreq.metaproprandom(mp; tau = :dl)
  Meta-proportion random-effect result:
  Weights (%): [22.204, 77.796]
  Estimate: 0.730277
  Variance  (Std. error): 0.0378703 (0.194603)
  Exp(Estimate): 2.07566
  Chi²: 14.3193
  Q: 0.236861
  I²: 0.0
  τ²: 0.0