Created
September 7, 2023 15:07
-
-
Save PatheticMustan/ec65235c34df1808791b8731fadcc890 to your computer and use it in GitHub Desktop.
calculate mean, std dev, and std err
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function magic(a) { | |
let N = a.length; | |
let mean = a.reduce((a,b)=>a+b,0) / N; | |
let sd = 0; | |
for (let i=0; i<a.length; i++) { | |
sd += ((a[i] - mean) ** 2); | |
} | |
sd /= N - 1; | |
sd = Math.sqrt(sd); | |
let sde = sd / Math.sqrt(N); | |
console.log(`mean: ${mean.toFixed(8)}`); | |
console.log(`standard deviation: ${sd.toFixed(8)}`); | |
console.log(`standard error: ${sde.toFixed(8)}`); | |
} | |
magic([ | |
1.69, 1.67, 1.69, 1.70, 1.74, 1.70, 1.74, 1.65, 1.79, 1.74 | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment