test_Covariance.praat 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # test_Covariance.praat
  2. # djmw 2015
  3. appendInfoLine: "test_Covariance"
  4. appendInfoLine: tab$, "Morrison_example_7.3"
  5. @test_Morrison_example_7_3
  6. appendInfoLine: tab$, "Morrison_example_3.5"
  7. @test_Morrison_example_3_5
  8. appendInfoLine: "test_Covariance OK"
  9. procedure test_Morrison_example_7_3
  10. .p = 2
  11. .k = 2
  12. .sm = Create simple Covariance: "sm", "4.32 1.88 9.18", "0 0", 32
  13. .numberOfColumns = Get number of columns
  14. .numberOfRows = Get number of rows
  15. assert .numberOfColumns = .p and .numberOfRows = .p; "nrows = ncols = 2"
  16. .numberOfObservations = Get number of observations
  17. assert .numberOfObservations = 32; "numberOfObservations" 'no' <> 32
  18. .dof = Get degrees of freedom
  19. assert .dof = .numberOfObservations - 1 ; "dof = no-1", 'dof'
  20. .x = Get centroid element: 1
  21. assert .x = 0
  22. .c11 = Get value: 1, 1
  23. .c22 = Get value: 2, 2
  24. assert .c11 = 4.32
  25. assert .c22 = 9.18
  26. .ln_det_sm = Get ln(determinant)
  27. .det_sm = exp (.ln_det_sm)
  28. .det_sm$ = fixed$ (.det_sm, 3)
  29. assert .det_sm$ = "36.123"
  30. .sf = Create simple Covariance: "sf", "2.52 1.90 10.06", "0 0", 32
  31. .ln_det_sf = Get ln(determinant)
  32. .det_sf = exp (.ln_det_sf)
  33. .det_sf$ = fixed$ (.det_sf, 3)
  34. assert .det_sf$ = "21.741"
  35. selectObject: .sm, .sf
  36. .report$ = Report equality of covariances
  37. .chisq = extractNumber (.report$, "Chi-squared (bartlett) = ")
  38. .chisq$ = fixed$ (.chisq, 2)
  39. assert .chisq$ = "2.72"
  40. .cInv = 1 - (2*.p^2+3*.p-1)/(6*(.p+1)*(.k-1))*(1/31+1/31-1/62)
  41. appendInfoLine: "C^-1 = ", .cInv
  42. removeObject: .sm, .sf
  43. endproc
  44. procedure test_Morrison_example_3_5
  45. .cor = Create simple Correlation: "correlation", "1.0 0.69 0.43 1.0 0.3 1.0", "0.0 0.0 0.0", 54
  46. .report$ = Get diagonality (bartlett): 1
  47. .chisq = extractNumber (.report$, "chisq = ")
  48. .chisq$ = fixed$ (.chisq, 2)
  49. assert .chisq$ = "43.54"
  50. .ln_det_r = Get ln(determinant)
  51. .det_r = exp (.ln_det_r)
  52. .det_r$ = fixed$ (.det_r, 3)
  53. assert .det_r$ = "0.427"
  54. removeObject: .cor
  55. endproc
  56. ;Difference