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](http://ncalculators.com/statistics/mean-standard-deviation-calculator.htm “Standard Deviation Calculator”)
-
#!/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
One Comment
Steps for Standard Deviation
Step 1 : Use formula for standard deviation,
σ = √[(1/N)Σi(xi-μ)2].
Step 2 : Where σ – the standard deviation
N – number of data points ;
xi – the random variable where i takes values from 1 to N ;
Step 3 : μ- the mean of the data set;
Then write the final answer for σ .
if you any large problem then i will suggest to use Standard Deviation Calculator Online