#require_relative 'lib/krippendorff_alpha' #STDEV: sample or population? #source = "6;7;8;9;10".split(";") source = [1,6,7,8,9,10,11] f = File.open("sd_source#{source.join(";")}.tsv","r:utf-8") users = Hash.new{|hash, key| hash[key] = Array.new} sds_of_values = Hash.new{|hash, key| hash[key] = Array.new} f.each_line.with_index do |line, index| if index > 0 line1 = line.strip.split for j in 5..5+source.length-1 if source[0] == 1 and j == 5 k = 1 else k = j end users[k] << line1[j].to_f end end end #STDERR.puts users.keys nvalues = users.values[0].length STDERR.puts nvalues def stats(input, type) if type == "hash" sent_array = input.values elsif type == "array" sent_array = input end sent_sum = 0.0 sent_array.each do |sent| sent_sum += sent end mean = sent_sum/sent_array.length sumsq = 0.0 sent_array.each do |sent| sumsq += (mean - sent)*(mean - sent) end sd = Math.sqrt(sumsq/sent_array.length) return mean, sd end def construct_combinations(source) combs = Hash.new{|hash, key| hash[key] = Array.new} for i in 1..source.length cands = source.permutation(i).to_a cands2 = [] cands.each do |cand| if !cands2.include?(cand.sort) cands2 << cand end end combs[i] = cands2 end return combs end combinations = construct_combinations(source) #STDERR.puts combinations for length in 1..source.length for combination in combinations[length] average_value_across_users = Array.new(nvalues, 0.0) for i in 0..nvalues-1 for user in combination average_value_across_users[i] += users[user][i] end end for k in 0..nvalues-1 average_value_across_users[k] = average_value_across_users[k]/length end sds_of_values[length] << stats(average_value_across_users, "array")[1] end end sds_of_values.each_pair do |length, sds| STDOUT.puts "#{length}\t#{stats(sds, "array")[0]}\t#{stats(sds, "array")[1]}\t#{combinations[length].length}" end