# try_chi01.rb.txt ruby script (encoding: Windows-31J) # 合計欄のないクロス集計表を読み込んでカイ二乗検定を行い、htmlを出力 # 目次付きのhtmlを生成(rubyライブラリのkramdownを利用) # data_chi01.csv を素材として z_chi01.htm を出力 # 素材表をグラフにした z_chi01.png を出力(モザイクプロット) # 途中で生成されるmarkdownの原稿 z_chi01.md.txt も出力 require "rrx" require "erb" # カイ二乗検定の結果から得られる項目+α item_csv = < ### 構成比(パーセント)\n <%= Rrx::matrix2table(pct1) %> ----------------\n ## クロス集計表のグラフ(モザイクプロット)\n ![モザイクプロットのグラフ](z_chi01.png)\n ----------------\n ## カイ二乗検定結果(表形式以外)\n  カイ二乗検定結果のうち、カイ二乗値、自由度、有意確率の値など\ 表形式でないものを示す。\n <%= Rrx::matrix2table(chi_item) %> ----------------\n ## カイ二乗検定結果(表形式)\n  以下に、カイ二乗検定結果のうち、期待値や残差等の表形式のものを掲げる。 <% chi_tbls.each do |title, val| %> <%= "### " + title + "\n" %> <%= Rrx::matrix2table(val) %> <% end %> EOS3 mkd_str = ERB.new(mkd_str).result(binding) File.open("z_chi01.md.txt", "w") {|ff| ff.write mkd_str} html_str = Rrx::kramdown_html(mkd_str, :s, :table, :toc_levels=>[2]) File.open("z_chi01.htm", "w") {|ff| ff.write html_str}