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
Open a new script
statistic_functions.jlin VSCode in a folder of your choice.implement a function called
rse_sum1. This function should returntrueif provided with the following test:rse_sum(1:36) == 666. You should further make use of a for-loop.implement a second function called
rse_mean, which calculates the mean of the provided vector. Make sure to use therse_sumfunction! Test it usingrse_mean(-15:17) == 1Next 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 withrse_std(1:3) == 1.Finally, we will implement
rse_tstat, returning the t-value withlength(x)-1DF, that the provided Array actually has a mean of 0. The formula is \(\frac{mean(x)}{std(x) / (sqrt(length(x)))}\) Test it withrse_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.
And thatβs it! You should have a nice progress bar now
Task 2
- Implement a type
StatResultwith fields forx,n,stdandtvalue - Implement an outer constructor that can run
StatResult(2:10)and return the full type including the calculated t-values. - Implement a function length for StatResult (using multiple-dispatch) which returns the
.nfield. Overload βBase.lengthβ - 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
rse = research software engineering, we could use
sumin a principled way, but it requires some knowledge you likely donβt have right nowβ©οΈ
