Skip to content

STD added to numericQuestionAnalysis - #314

Open
anna-harrington-7 wants to merge 2 commits into
mainfrom
origin/281-Add-STD-to-numericQuestionAnalytics
Open

STD added to numericQuestionAnalysis#314
anna-harrington-7 wants to merge 2 commits into
mainfrom
origin/281-Add-STD-to-numericQuestionAnalytics

Conversation

@anna-harrington-7

Copy link
Copy Markdown
Contributor

Added std deviation calculations and displays on website

Description

Relevant issue(s)

Questions

  • I am 90% sure this works, though I don't think this is the best way to do it?

Type of change

  • [ x] New feature (non-breaking change which adds functionality)

Checklist:

  • [x ] My code follows the style guidelines of this project
  • [ x] I have performed a self-review of my code
  • [ x] My changes generate no new warnings
  • [ x] I have assigned reviewers to this PR

Added std deviation calculations and displays on website
@jmcheek jmcheek linked an issue Apr 20, 2025 that may be closed by this pull request

@jmcheek jmcheek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@anna-harrington-7

Copy link
Copy Markdown
Contributor Author

Fixed the formula

@jmcheek jmcheek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep this :)

// calculate mean for std
stdMean = ((total / numbers.length) * 100) / 100;
sdTotal += Math.pow(number - stdMean, 2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove line 43, and move line 44 into a separate loop


// Rounds standard deviation to hundredths place
standardDeviation = Math.round(standardDeviation * 100) / 100;

@jmcheek jmcheek Apr 25, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Standard Deviation to NumericQuestionAnalytics

2 participants