API
Contingency tables
MetidaFreq.contab
MetidaFreq.contab
— Functioncontab(m::AbstractMatrix{Int};
rownames::Union{Vector{String}, Nothing} = nothing,
colnames::Union{Vector{String}, Nothing} = nothing,
id::Dict = Dict())
contab(v::AbstractVector{Int};
rownames::Union{Vector{String}, Nothing} = nothing,
colnames::Union{Vector{String}, Nothing} = nothing,
id::Dict = Dict())
contab(ct::ConTab, rr, cr)
Make ConTab with ct
, rows rr
and columns cr
.
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.
MetidaFreq.freq
MetidaFreq.freq
— Functionfreq(data, col; id = Dict())
Return frequencies as ix1 contingency table.
freq(data::AbstractVector; id = Dict())
Return frequencies as ix1 contingency table.
MetidaFreq.freqdict
MetidaFreq.freqdict
— Functionfreqdict(data::AbstractVector)
Return frequencies as Dict
.
Contingency tables utilities
MetidaFreq.addcol
MetidaFreq.addcol
— Functionaddcol(ct::ConTab, col::Vector{Int}; coln = "Val")
Add column.
addcol(f::Function, ct::ConTab; coln = "Val")
Apply function to row and make new column.
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.
MetidaFreq.colorder
MetidaFreq.colorder
— Functioncolorder(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;
MetidaFreq.colreduce
MetidaFreq.colreduce
— Functioncolreduce(f::Function, data::DataSet{<:ConTab}; coln = nothing)
Sum rows for each table, than make new table where in each column pleced sums.
MetidaFreq.dropzeros!
MetidaFreq.dropzeros!
— Functiondropzeros!(ds::DataSet{<:ConTab})
Drop tables from dataset if no observation.
Base.permutedims
Base.permutedims
— FunctionBase.permutedims(ct::ConTab)
ConTab permutedims.
MetidaFreq.sumrows
MetidaFreq.sumrows
— Functionsumrows(f::Function, contab::ConTab; coln = "Val")
Aplpy function to each element of row, sum and make new column.
sumrows(contab::ConTab; coln = "Val")
Aplpy identity
function to each element of row, sum and make new column.
Confidence Intervals
MetidaFreq.confint
StatsAPI.confint
— FunctionStatsBase.confint(mpr::MetaPropResult; level = 0.95)
Confidence interval for pooled proportion.
!!! Warn Results are in log-scale for OR and RR.
MetidaFreq.propci
MetidaFreq.propci
— Functionpropci(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.
propci(contab::ConTab; level = 0.95, method = :default)
propci(prop::Proportion; level = 0.95, method = :default)
MetidaFreq.diffci
MetidaFreq.diffci
— Functiondiffci(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.
diffci(contab::ConTab; level = 0.95, method = :default)
ConTab 2X2:
A | B
--|--
C | D
Difference: A / (A + B) - C / (C + D)
MetidaFreq.orci
MetidaFreq.orci
— Functionorci(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.
orci(contab::ConTab; level = 0.95, method = :default)
A | B
--|--
C | D
Odd ratio: (A / B) / (C / D)
MetidaFreq.rrci
MetidaFreq.rrci
— Functionrrci(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.
rrci(contab::ConTab; level = 0.95, method = :default)
A | B
--|--
C | D
Risk ratio: (A / (A + B)) / (C / (C + D)
MetidaFreq.mpropci
MetidaFreq.mpropci
— Functionmpropci(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.
Meta-analysis
MetidaFreq.metaprop
MetidaFreq.metaprop
— Functionmetaprop(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.
MetidaFreq.metapropfixed
MetidaFreq.metapropfixed
— Functionmetapropfixed(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.**
MetidaFreq.metaproprandom
MetidaFreq.metaproprandom
— Functionmetaproprandom(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)
Base
Base.getindex
Base.getindex
— FunctionBase.getindex(ct::ConTab, args...) = getindex(ct.tab, args...)
Returns values of Contab by index.
HypothesisTests
HypothesisTests.ChisqTest
HypothesisTests.ChisqTest
— FunctionHypothesisTests.ChisqTest(contab::ConTab)
HypothesisTests.MultinomialLRTest
HypothesisTests.MultinomialLRTest
— FunctionHypothesisTests.MultinomialLRTest(contab::ConTab)
HypothesisTests.FisherExactTest
HypothesisTests.FisherExactTest
— TypeHypothesisTests.FisherExactTest(contab::ConTab)
Experimental
MetidaFreq.oddsci
MetidaFreq.oddsci
— Functionoddsci(xa, xb; level = 0.95, method = :default)
Confidence interval for odd where total number n = xa + xb.
oddsci(contab::ConTab; level = 0.95, method = :default)