Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- import math
- # An imaginary dataset of 50 respondents graded from 1-9, so we have an example to play with:
- dataset = [1,1,1,2,3,1,1,4,4,5,6,1,4,9,9,7,7,6,7,5,4,3,6,8,9,5,5,6,6,6,5,5,5,5,4,4,4,6,6,4,7,3,7,3,7,4,4,4,4,9]
- # Amounts of each: 1*6,2*1,3*4,4*12,5*8,6*8,7*6,8*1,9*4
- # Control: 6+1+4+12+8+8+6+1+4=50
- # the mean average (the arithmetic mean) is the sum of all the grades added together, divided by the amount of grades given
- mean = sum(dataset)/len(dataset)
- # the deviation is calculated as (grade-mean)^2 for each grade in the dataset
- deviation = [ (grade-mean)**2 for grade in dataset ]
- # the variance is simply the mean of the deviations
- variance = sum(deviation)/len(deviation)
- # lastly, the standard deviation is the square root of the variance
- standard_deviation = math.sqrt(variance)
- print (standard_deviation)
- # You can now use the standard deviation in the integration of Gaussian distributions
Add Comment
Please, Sign In to add comment