Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. ONES = J(N, 1, 1);
  2. meanvec = (1/N)*t(X)*ONES;
  3. mean_matrix = ONES*t(meanvec);
  4. cov_matrix = (1/n) * t(X- mean_matrix) * (x - mean_matrix);
  5.  
  6. ONES <- matrix(1, nrow=N, ncol=1)
  7. meanvec <- (1/N) * t(X) %*% ONES
  8. mean_matrix <- ONES %*% t(meanvec)
  9. cov_matrix <- (1/N) * t(X - mean_matrix) %*% (X - mean_matrix)
  10.  
  11. X
  12. [,1] [,2] [,3]
  13. [1,] 90 60 90
  14. [2,] 90 90 30
  15. [3,] 60 60 60
  16. [4,] 60 60 90
  17. [5,] 30 30 30
  18.  
  19. cov_matrix
  20. [,1] [,2] [,3]
  21. [1,] 504 360 180
  22. [2,] 360 360 0
  23. [3,] 180 0 720
  24.  
  25. cov(X)
  26. [,1] [,2] [,3]
  27. [1,] 630 450 225
  28. [2,] 450 450 0
  29. [3,] 225 0 900
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement