Task 1

Wait - how do I even run things in Julia/VScode?

Typically, you work in a Julia script ending in scriptname.jl

You concurrently have a REPL open, to not reload all packages etc. everytime. Further you typically have Revise.jl running in the background to automatically update your custom Packages / Modules (more to that later).

You can mark some code and execute it using ctrl + enter - you can also generate code-blocks using #--- and run a whole code-block using alt+enter

The exercise

  1. Open a new script statistic_functions.jl in VSCode in a folder of your choice.

  2. implement a function called rse_sum1. This function should return true if provided with the following test: rse_sum(1:36) == 666. You should further make use of a for-loop.

  3. implement a second function called rse_mean, which calculates the mean of the provided vector. Make sure to use the rse_sum function! Test it using rse_mean(-15:17) == 1

  4. Next implement a standard deviation function rse_std: \(\sqrt{\frac{\sum((x-mean(x))^2)}{n-1}}\), this time you should use elementwise/broadcasting operators. Test it with rse_std(1:3) == 1.

  5. Finally, we will implement rse_tstat, returning the t-value with length(x)-1 DF, that the provided Array actually has a mean of 0. The formula is \(\frac{mean(x)}{std(x) / (sqrt(length(x)))}\) Test it with rse_tstat(2:3) == 5.. Add the keyword argument Οƒ that allows the user to optionally provide a pre-calculated standard deviation.

Well done! You now have all functions defined with which we will continue our journey.

Bonus Task ProgressMeter

for very large sums we might want to add a progressmeter. To do so:

]add ProgressMeter
using ProgressMeter
...
@showprogress for ...

And that’s it! You should have a nice progress bar now

Task 2

  1. Implement a type StatResult with fields for x, n, std and tvalue
  2. Implement an outer constructor that can run StatResult(2:10) and return the full type including the calculated t-values.
  3. Implement a function length for StatResult (using multiple-dispatch) which returns the .n field. Overload β€œBase.length”
  4. Optional: If you have time, optimize the functions, so that mean, sum, length, std etc. is not calculated multiple times - you might want to rewrite your type. Note: This is a bit tricky :)

Footnotes

  1. rse = research software engineering, we could use sum in a principled way, but it requires some knowledge you likely don’t have right nowβ†©οΈŽ