STD added to numericQuestionAnalysis - #314
Conversation
Added std deviation calculations and displays on website
jmcheek
left a comment
There was a problem hiding this comment.
Looks good on the page, but I believe you squared the sum of the deviations rather than taking the sum the squared deviations. If you fix that, it should be good to go!
|
Fixed the formula |
jmcheek
left a comment
There was a problem hiding this comment.
Close, but you actually calculate the mean as you looped through the numbers. Instead you'll want to move the mean calculation outside the first loop. Then loop through again and calculate the variance, then you'll divide that by numbers.length and root to get standard deviation.
| @@ -35,6 +38,11 @@ export default function NumericQuestionAnalytics({ | |||
| const number = questionResponse.answer; | |||
| total += number; | |||
| numbers.push(number); | |||
| // calculate mean for std | ||
| stdMean = ((total / numbers.length) * 100) / 100; | ||
| sdTotal += Math.pow(number - stdMean, 2); | ||
|
|
There was a problem hiding this comment.
remove line 43, and move line 44 into a separate loop
|
|
||
| // Rounds standard deviation to hundredths place | ||
| standardDeviation = Math.round(standardDeviation * 100) / 100; | ||
|
|
There was a problem hiding this comment.
You'll want to calculate the mean here, your line 43 should work I believe ->
const mean = total / numbers.length
You then want to loop through and calculate the variance, and then the standard deviation
so, use your line 44 here
for (const num of numbers){
sdTotal += Math.pow(number - stdMean, 2)
}
then leave line 83 just as you have it outside the loop, and your done!
Added std deviation calculations and displays on website
Description
Relevant issue(s)
Questions
Type of change
Checklist: