Google+ Tools
Make Google+ profile picture
Make Google plus banners for profile
Create and share your Google Plus profile banners.

Profile image for mrk studios vinotht on August 22, 2011

This below code is for calculate standard deviation in Ruby on Rails. Here the data set is given in a array. To know more about standard deviation calculations @ Standard Deviation Calculator

Language
Ruby
Tags

Calculate Standard Deviation in Ruby


#!/usr/bin/ruby -w
include Math
#Data we are going to calculate stdev
arrValues = [ 4.58, 4.53, 4.1, 4.05 ]
fMedian = 0
arrValues.each do |fValue|
fMedian += fValue
end
fMedian /= arrValues.size.to_f
puts "Mittelwert = " + fMedian.to_s
fStandardDeviation = 0
arrValues.each do |fValue|
fStandardDeviation += (fValue - fMedian)**2
end
puts "Zwischensumme = " + fStandardDeviation.to_s
fStandardDeviation /= arrValues.size.to_f
puts fStandardDeviation
fStandardDeviation = Math.sqrt(fStandardDeviation)
fStandardDeviation = "%.3f" % fStandardDeviation
puts "rating = " + fStandardDeviation.to_s

Comments

blog comments powered by Disqus