studentt.R 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. # This script generates a JSON file with various values of Student's t-distribution.
  2. # The results will be compared with the one's obtained with the JavaScript implementation.
  3. dfs <- c(1, 2, 2.5, 5, 10, 10.1, 50, 50.1)
  4. ts <- c(-10, -5, -2, -1, -0.5, 0, 0.5, 1, 2, 5, 10)
  5. ps <- c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9)
  6. pdfstr <- ' "pdf": [\n'
  7. for (df in dfs) {
  8. for (t in ts) {
  9. pdfstr <- paste0(pdfstr, sprintf(' [%.2e, %.2e, %.16e],\n', t, df, dt(t, df)))
  10. }
  11. }
  12. pdfstr <- paste0(substring(pdfstr, 1, nchar(pdfstr) - 2), ' \n]')
  13. cdfstr <- ' "cdf": [\n'
  14. for (df in dfs) {
  15. for (t in ts) {
  16. cdfstr <- paste0(cdfstr, sprintf(' [%.2e, %.2e, %.16e],\n', t, df, pt(t, df)))
  17. }
  18. }
  19. cdfstr <- paste0(substring(cdfstr, 1, nchar(cdfstr) - 2), ' \n]')
  20. ppfstr <- ' "ppf": [\n'
  21. for (df in dfs) {
  22. for (p in ps) {
  23. ppfstr <- paste0(ppfstr, sprintf(' [%.2e, %.2e, %.16e],\n', p, df, qt(p, df)))
  24. }
  25. }
  26. ppfstr <- paste0(substring(ppfstr, 1, nchar(ppfstr) - 2), ' \n]')
  27. write(paste0('{\n', pdfstr, ',\n', cdfstr, ',\n', ppfstr, '\n}\n'), file='assets/studentt.json')