Methods

Class/Module Index [+]

Quicksearch

Statsample::Mx

Public Class Methods

write(dataset,filename,type=:covariance) click to toggle source
# File lib/statsample/converters.rb, line 246
def write(dataset,filename,type=:covariance)
  puts "Writing MX File"
  File.open(filename,"w") do |fp|
    fp.puts "! #{filename}"
    fp.puts "! Output generated by Statsample"
    fp.puts "Data Ninput=#{dataset.fields.size} Nobservations=#{dataset.cases}"
    fp.puts "Labels "+dataset.fields.join(" ")
    case type
      when :raw
      fp.puts "Rectangular"
      dataset.each do |row|
        out=dataset.fields.collect do |f|
          if dataset[f].is_valid? row[f]
            row[f]
          else
            "."
          end
        end
        fp.puts out.join("\t")
      end
      fp.puts "End Rectangular"
    when :covariance
      fp.puts " CMatrix Full"
      cm=Statsample::Bivariate.covariance_matrix(dataset)
      d=(0...(cm.row_size)).collect {|row|
        (0...(cm.column_size)).collect{|col|
          cm[row,col].nil? ? "." : sprintf("%0.3f", cm[row,col])
        }.join(" ")
      }.join("\n")
      fp.puts d
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.