Skip to content

Instantly share code, notes, and snippets.

@slimane
Forked from anonymous/stat.hs
Created December 6, 2013 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slimane/7819060 to your computer and use it in GitHub Desktop.
Save slimane/7819060 to your computer and use it in GitHub Desktop.
{-
summary :
odds比を計算
detail :
与えられた群Aと、(全体-群A)との発生率との比を計算
args :
total --全体の数
incidence --全体の発生数
a_total --群Aの全体数
a_incidence --群Aの発生数
-}
odd_ratio total incidence a_total a_incidence =
(a_incidence / a_total) / (incidence_exclude_a / total_exclude_a)
where
total_exclude_a = total - a_total
incidence_exclude_a = incidence - a_incidence
{-
summary :
適合度検定(カイ2乗検定)の計算
detail :
与えられた群Aと、(全体-群A)との発生数から適合度検定を実施
args :
total --全体の数
incidence --全体の発生数
a_total --群Aの全体数
a_incidence --群Aの発生数
-}
chisq total incidence a_total a_incidence =
chisq' a_incidence estimate_incidence
+ chisq' a_no_incidence estimate_no_incidence
where
rate = (incidence - a_incidence) / (total - a_total) --(全体-群A)の発生率
estimate_incidence = a_total * rate --a群の予想発生数
estimate_no_incidence = a_total * (1 - rate) --a群の予想非発生数
a_no_incidence = a_total - a_incidence --a群の非発生数
chisq' actual estimate = (actual - estimate)**2 / estimate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment