Guest User

Untitled

a guest
May 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. import math
  3.  
  4. # An imaginary dataset of 50 respondents graded from 1-9, so we have an example to play with:
  5. 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]
  6. # Amounts of each: 1*6,2*1,3*4,4*12,5*8,6*8,7*6,8*1,9*4
  7. # Control: 6+1+4+12+8+8+6+1+4=50
  8.  
  9. # the mean average (the arithmetic mean) is the sum of all the grades added together, divided by the amount of grades given
  10. mean = sum(dataset)/len(dataset)
  11.  
  12. # the deviation is calculated as (grade-mean)^2 for each grade in the dataset
  13. deviation = [ (grade-mean)**2 for grade in dataset ]
  14.  
  15. # the variance is simply the mean of the deviations
  16. variance = sum(deviation)/len(deviation)
  17.  
  18. # lastly, the standard deviation is the square root of the variance
  19. standard_deviation = math.sqrt(variance)
  20.  
  21. print (standard_deviation)
  22.  
  23. # You can now use the standard deviation in the integration of Gaussian distributions
Add Comment
Please, Sign In to add comment