function [stat,asc] = contgd(X,sig)

// 2x2 contingency

// X ... data marix of absolute frequencies
// sig ... significance level of association (default 0.05)

// asc ... association coefficient
// stat ... chi-square computed stat. and quantil [computed tabulated]

// Literature: Dowdy, S., Wearden, S. and Chilko, D. (2004). Statistics
// for research, Wiley: New Jersey

// Copyright (C): Lukáš Malec; University of Business in Prague,
// Czech Republic
// Date: $2015-12-19$

[lhs,rhs]=argn(0)

if X==[] then asc=%nan, return, end

[n,m] = size(X), sX = sum(X)

if n <> 2|m <> 2 then
    error(msprintf(gettext("%s: Bad size of input matrix\n"),"Error #1"))

end

rsum = sum(X,1), csum = sum(X,2)

Xt = []
for i = 1:2
    for j = 1:2
        Xt(i,j) = rsum(j)*csum(i)/sX

    end
end

f = find(Xt < 5)
if length(f) > 0 then
    error(msprintf(gettext("%s: The condition on theoretical...
 frequencies is not satisfied\n"),"Error #2"))

end

rsum = sum(X,1), csum = sum(X,2)

asc = (X(1,1)*X(2,2) - X(1,2)*X(2,1)) /sqrt(prod([rsum' csum]))

if rhs==1
    sig = 0.05

end

chip = sX*(X(1,1)*X(2,2) - X(1,2)*X(2,1))^2 /(prod([rsum' csum]))
chi = cdfchi("X",1,1-sig,sig)

stat = [chip chi]

if chip > chi then
    mprintf(gettext("%s: The null hypothesis of no association...
 is rejected\n"),"H0 decision")
else
    mprintf(gettext("%s: The null cannot be rejected\n"),"H0 decision")
    
end

endfunction
