Julia, Software Development, Statistics

Find Standard Deviation In Julia

Although there is the Statistics.std function, this post shows how to find the Standard Deviation in Julia using custom codes.

What is Standard Deviation?

The Standard Deviation is a value that shows how much the values deviate from their mean. A low value means less amount of variation or dispersion of sample values, while a high value means the values are spread out over a wider range.

Julia Codes Standard Deviation

We are going to use the Statistics Package for the mean function. Let us begin with a sample of integers. For proceeding, please ensure we have Julia installed in our system.

Then, we find the mean using the Statistics.mean function.

Next, find the number of values in the sample.

For each value, we subtract it with the samples_mean and square the difference.  The Standard Deviation is relative to the mean of the sample values. Then, we sum up these results.

Lastly, we find the square root of the sum over samples_size - 1 to find the Standard Deviation in Julia.

Create a Standard Deviation Function

To reuse the codes anywhere, we can put them in a function for finding the Standard Deviation of sample values. We name the function my_std. Its definition is as follows. We still need the Statistics Package for the mean function.

The complete Julia codes for finding the Standard Deviation, including the function’s usage, are as follows. Notice the function comes before its usage.

The codes produce the following output.

If we know how to complete the Standard Deviation, creating codes in Julia to find the Standard Deviation comes naturally.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like