Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: standardError #257

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat: standardError #257

wants to merge 2 commits into from

Conversation

Yomguithereal
Copy link
Member

@Yomguithereal Yomguithereal commented Oct 16, 2017

Adding the standardError function to the library.

Some interrogations:

  • What should we return when the list has only 1 element? 0 as done now?
  • What should we do with an empty list? Throw? (Note that this case is not addressed with the standardDeviation function either).
  • Should we also add sampleStandardError with Bessel's correction?

Note that I can add some unit tests to reflect our choices on the first two questions.

@Yomguithereal
Copy link
Member Author

Related to #203.

@Yomguithereal
Copy link
Member Author

Nobody wants standard error :(. Sadness fills my heart.

@Yomguithereal
Copy link
Member Author

Bump?

@jwilber
Copy link
Contributor

jwilber commented Apr 23, 2018

For your first two interrogations,

What should we return when the list has only 1 element? 0 as done now?
What should we do with an empty list? Throw? (Note that this case is not addressed with the standardDeviation function either).

I vote for both we return nan .
I'd have to review, but I believe in either case we'll have degrees of freedom for our estimates <= 0.
This also mirrors how both R and scipy handle such cases.

scipy.stats.sem also has a policy for handling nan returns, (e.g. throw or return nan) - maybe you could add something similar?

@tmcw
Copy link
Member

tmcw commented Jun 14, 2020

@Yomguithereal @jwilber I've rebased and cleaned up this branch - sorry, wasn't very familiar with standard error the concept, the delay on this one is 😢.

The current state of the branch is that throws with [] input, like other methods, and returns 0 on single-element input, which seems like the right approach given that std_dev / sqrt(length) returns 0 naively. If that's good for you folks, I'll merge and release with this (thanks @Yomguithereal and sorry for the epic delay :/)

@Yomguithereal
Copy link
Member Author

@tmcw so everything's alright with current code? Do you want me to add TS definition file?

throw new Error("standardError is not defined for empty arrays");
}

return standardDeviation(x) / Math.sqrt(x.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: is the name standardError too general given that this is only the standard error of the sample mean?

* standardError([2, 4, 4, 4, 5, 5, 7, 9]); // => 2 / Math.sqrt(8)
*/
function standardError(x /*: Array<number> */) /*:number*/ {
if (x.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be removed and standardDeviation itself allowed to throw?

> ss.standardDeviation([]) / 0
Uncaught Error: variance requires at least one data point
    at variance (/home/dsaxton/simple-statistics/dist/simple-statistics.js:226:15)
    at Object.standardDeviation (/home/dsaxton/simple-statistics/dist/simple-statistics.js:254:13)

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

Successfully merging this pull request may close these issues.

None yet

4 participants