API

Contingency tables

MetidaFreq.contab

MetidaFreq.contabFunction
contab(m::AbstractMatrix{Int};
    rownames::Union{Vector{String}, Nothing} = nothing,
    colnames::Union{Vector{String}, Nothing} = nothing,
    id::Dict = Dict())
source
contab(v::AbstractVector{Int};
    rownames::Union{Vector{String}, Nothing} = nothing,
    colnames::Union{Vector{String}, Nothing} = nothing,
    id::Dict = Dict())
source
contab(ct::ConTab, rr, cr)

Make ConTab with ct, rows rr and columns cr.

source
contab(data, row::Symbol, col::Symbol; sort::Union{Nothing, Symbol, AbstractVector{Symbol}} = nothing, id = nothing)

Make contingency table from data using row and col columns.

source

MetidaFreq.freq

Contingency tables utilities

MetidaFreq.addcol

MetidaFreq.addcolFunction
addcol(ct::ConTab, col::Vector{Int}; coln = "Val")

Add column.

source
addcol(f::Function, ct::ConTab; coln = "Val")

Apply function to row and make new column.

source
addcol(f::Function, ct::ConTab, col::Vector{Int}; coln = "Val")

Example function (x,y) -> sum(x) + y, where x - row, y - value of col item.

source

MetidaFreq.colorder

MetidaFreq.colorderFunction
colorder(ct::ConTab, v::AbstractVector{AbstrctString})

Make contigency trable with column order as in v vector. If item in v not present in tab collumn's names - collumn of zeros will be made for that item.

Example

Contingency table:
--------- -------- ----- -------
              B      D    Total 
--------- -------- ----- -------
   G1         1     123     124
   G2         0     124     124
--------- -------- ----- -------
 ID: ColName => id;

after colorder(ct, ["A", "B", "C", "D"]):

Contingency table:
--------- -------- --------- --------- ----- -------
              A         B         C      D    Total 
--------- -------- --------- --------- ----- -------
    G1        0         1         0     123     124
    G2        0         0         0     124     124
--------- -------- --------- --------- ----- -------
ID: ColName => id;
source

MetidaFreq.colreduce

MetidaFreq.colreduceFunction
colreduce(f::Function, data::DataSet{<:ConTab}; coln = nothing)

Sum rows for each table, than make new table where in each column pleced sums.

source

MetidaFreq.dropzeros!

Base.permutedims

MetidaFreq.sumrows

MetidaFreq.sumrowsFunction
sumrows(f::Function, contab::ConTab; coln = "Val")

Aplpy function to each element of row, sum and make new column.

source
sumrows(contab::ConTab; coln = "Val")

Aplpy identity function to each element of row, sum and make new column.

source

Confidence Intervals

MetidaFreq.confint

StatsAPI.confintFunction
StatsBase.confint(mpr::MetaPropResult; level = 0.95)

Confidence interval for pooled proportion.

!!! Warn Results are in log-scale for OR and RR.

source

MetidaFreq.propci

MetidaFreq.propciFunction
propci(x::Int, n::Int; level = 0.95, method = :default)

Proportion confidence interval.

method:

  • :wilson | :default - Wilson's confidence interval (CI) for a single proportion (wilson score) (Wilson, 1927);
  • :wilsoncc - Wilson's CI with continuity correction (CC);
  • :cp - Clopper-Pearson exact CI (Clopper&Pearson, 1934);
  • :blaker - Blaker exact CI for discrete distributions (Blaker, 2000);
  • :soc - SOC: Second-Order corrected CI;
  • :arc - Arcsine CI;
  • :wald - Wald CI without CC;
  • :waldcc - Wald CI with CC (1/2/n);
  • :ac - Agresti-Coull;
  • :jeffrey - Jeffreys interval (Brown et al,2001).

Reference:

  • Wilson, E.B. (1927) Probable inference, the law of succession, and statistical inference J. Amer.Stat. Assoc 22, 209–212;
  • Clopper, C. and Pearson, E.S. (1934) The use of confidence or fiducial limits illustrated in the caseof the binomial.Biometrika26, 404–413;
  • Agresti A. and Coull B.A. (1998) Approximate is better than "exact" for interval estimation of binomial proportions. American Statistician, 52, pp. 119-126.
  • Newcombe, R. G. (1998) Two-sided confidence intervals for the single proportion: comparison of seven methods, Statistics in Medicine, 17:857-872 https://pubmed.ncbi.nlm.nih.gov/16206245/
  • Blaker, H. (2000). Confidence curves and improved exact confidence intervals for discrete distributions, Canadian Journal of Statistics 28 (4), 783–798;
  • Pires, Ana & Amado, Conceição. (2008). Interval Estimators for a Binomial Proportion: Comparison of Twenty Methods. REVSTAT. 6. 10.57805/revstat.v6i2.63.
source
propci(contab::ConTab; level = 0.95, method = :default)
source
propci(prop::Proportion; level = 0.95, method = :default)
source

MetidaFreq.diffci

MetidaFreq.diffciFunction
diffci(x1, n1, x2, n2; level = 0.95, method = :default)

Proportion difference (x1 / n1 - x2 / n2) confidence interval.

  • 'method'

  • :mn | :default- Miettinen & Nurminen; Miettinen, O. and Nurminen, M. (1985), Comparative analysis of two rates. Statist. Med., 4: 213-226. doi:10.1002/sim.4780040211;

  • :fm | :mee - Mee maximum likelihood method; Mee RW (1984) Confidence bounds for the difference between two probabilities,Biometrics40:1175-1176

  • :wald - Wald CI without CC;

  • :waldcc - Wald CI with CC;

  • :nhs - Newcombes Hybrid (wilson) Score interval; Newcombe RG (1998), Interval Estimation for the Difference Between Independent Proportions: Comparison of Eleven Methods. Statistics in Medicine 17, 873-890;

  • :nhscc - Newcombes Hybrid Score CC; Newcombe (1998);

  • :ac - Agresti-Caffo interval; Agresti A, Caffo B., “Simple and effective confidence intervals for proportions and differences of proportions result from adding two successes and two failures”, American Statistician 54: 280–288 (2000);

  • :ha - Hauck-Andersen; Hauck, W. W., & Anderson, S. (1986). A Comparison of Large-Sample Confidence Interval Methods for the Difference of Two Binomial Probabilities. The American Statistician, 40(4), 318–322. doi:10.1080/00031305.1986.10475426 ;

  • :mover - Method of variance estimates recovery;

  • :jeffrey - Brown, Li's Jeffreys.

Reference:

  • Brown, L.D., Cai, T.T., and DasGupta, A. Interval estimation for a binomial proportion. Statistical Science, 16(2):101–117, 2001.
  • Farrington, C. P. and Manning, G. (1990), “Test Statistics and Sample Size Formulae for Comparative Binomial Trials with Null Hypothesis of Non-zero Risk Difference or Non-unity Relative Risk,” Statistics in Medicine, 9, 1447–1454
  • Li HQ, Tang ML, Wong WK. Confidence intervals for ratio of two Poisson rates using the methodof variance estimates recovery. Computational Statistics 2014; 29(3-4):869-889
  • Brown, L., Cai, T., & DasGupta, A. (2003). INTERVAL ESTIMATION IN EXPONENTIAL FAMILIES. Statistica Sinica, 13(1), 19-49.
source
diffci(contab::ConTab; level = 0.95, method = :default)

ConTab 2X2:

A | B
--|--
C | D

Difference: A / (A + B) - C / (C + D)

source

MetidaFreq.orci

MetidaFreq.orciFunction
orci(x1, n1, x2, n2; level = 0.95, method = :default)

Odd ratio confidence interval.

  • :mn - MN Score (Miettinen&Nurminen, 1985);
  • :fm | :mee - FM (same as MN Score, but not multiplied on (n1 + n2) * (n1 + n2 - 1)) (Mee RW, 1984; Farrington&Manning, 1990);
  • :woolf - Woolf logit (Woolf, 1955);
  • :awoolf - Adjusted Woolf interval (Gart adjusted logit) (Gart, 1966; Lawson, 2005);
  • :mover - Method of variance estimates recovery (MOVER) (Donner&Zou, 2012);

Reference:

  • Miettinen O. S., Nurminen M. (1985) Comparative analysis of two rates.Statistics in Medicine 4,213–226;
  • Mee RW (1984) Confidence bounds for the difference between two probabilities,Biometrics 40:1175-1176;
  • Farrington, C. P. and Manning, G. (1990), “Test Statistics and Sample Size Formulae for Comparative Binomial Trials with Null Hypothesis of Non-zero Risk Difference or Non-unity Relative Risk,” Statistics in Medicine, 9, 1447–1454;
  • Woolf, B. (1955). On estimating the relation between blood group and disease. Annals of human genetics, 19(4):251-253;
  • Gart, J. J. (1966). Alternative analyses of contingency tables. Journal of the Royal Statistical Society. Series B (Methodological), 28:164-179;
  • Lawson, R (2005). Smallsample confidence intervals for the odds ratio. Communication in Statistics Simulation and Computation, 33, 1095-1113;
  • Donner, A. and Zou, G. (2012). Closed-form confidence intervals for functions of the normal mean and standard deviation. Statistical Methods in Medical Research, 21(4):347-359.
source
orci(contab::ConTab; level = 0.95, method = :default)
A | B
--|--
C | D

Odd ratio: (A / B) / (C / D)

source

MetidaFreq.rrci

MetidaFreq.rrciFunction
rrci(x1, n1, x2, n2; level = 0.95, method = :default)

Risk ratio confidence interval.

  • :mn - Miettinen-Nurminen Score interval (Miettinen&Nurminen, 1985);
  • :fm | :mee - FM Score interval (Mee RW, 1984; Farrington&Manning, 1990);
  • :cli - Crude log interval, Gart (Gart&Nam, 1988);
  • :li | :wald - Log interval / Katz / Wald interval (Katz et al, 1978);
  • :mover - Method of variance estimates recovery (Donner&Zou, 2012);

Reference:

  • Miettinen, O. and Nurminen, M. (1985), Comparative analysis of two rates. Statist. Med., 4: 213-226. doi:10.1002/sim.4780040211;
  • Mee RW (1984) Confidence bounds for the difference between two probabilities,Biometrics 40:1175-1176;
  • Farrington, C. P., & Manning, G. (1990). Test statistics and sample size formulae for comparative binomial trials with null hypothesis of non-zero risk difference or non-unity relative risk. Statistics in Medicine, 9(12), 1447–1454. doi:10.1002/sim.4780091208;
  • Gart, JJ and Nam, J (1988): Approximate interval estimation of the ratio of binomial parameters: Areview and corrections for skewness. Biometrics 44, 323-338;
  • Katz D, Baptista J, Azen SP and Pike MC. Obtaining confidence intervals for the risk ratio in cohort studies. Biometrics 1978; 34: 469–474;
  • Donner, A. and Zou, G. (2012). Closed-form confidence intervals for functions of the normal mean and standard deviation. Statistical Methods in Medical Research, 21(4):347-359.
source
rrci(contab::ConTab; level = 0.95, method = :default)
A | B
--|--
C | D

Risk ratio: (A / (A + B)) / (C / (C + D)

source

MetidaFreq.mpropci

MetidaFreq.mpropciFunction
mpropci(contab::ConTab; level = 0.95, method = :default)

Multinomial proportions confidence interval.

method:

  • goodman | default Goodman, L.A. (1965). On Simultaneous Confidence Intervals for Multinomial Proportions. Technometrics 7: 247-254.
source

Meta-analysis

MetidaFreq.metaprop

MetidaFreq.metapropFunction
metaprop(d, metric; adj = 0)

Meta-analysis for 2x2 tables. Where:

d: `DataSet{ConTab}

metric:

  • :rr (Risk Ratio)
  • :or (Odd Ratio)
  • :diff (Risk Difference)

adj - adjustment value.

source

MetidaFreq.metapropfixed

MetidaFreq.metapropfixedFunction
metapropfixed(mp; weights = :default)

Inverce Variance method used by default.

weights:

  • :iv | :default (Inverce Variance)
  • :mh (Mantel Haenszel)

For Risk Difference Sato, Greenland, & Robins (1989) modification for variance estimation used.

*Results for RR and OR are in log-scale.**

source

MetidaFreq.metaproprandom

MetidaFreq.metaproprandomFunction
metaproprandom(mp; tau = :default)

tau - τ² calculation method:

  • :dl DerSimonian-Laird (by default)
  • :ho Hedges - Olkin
  • :hm Hartung and Makambi (Veroniki et al. 2016)
  • :sj Sidik and Jonkman
  • :ml Maximum likelihood (ML) method (Veroniki et al. 2016)
  • :reml Restricted maximum likelihood (REML) method (Veroniki et al. 2016)
source

HypothesisTests

HypothesisTests.ChisqTest

HypothesisTests.MultinomialLRTest

HypothesisTests.FisherExactTest