Advertisement
Guest User

calcsd volume

a guest
Sep 7th, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. # Average values are from old CalcSD site, not sure if it's still accurate
  5. mean_length = 13.98
  6. sd_length = 1.72
  7.  
  8. mean_girth = 11.64
  9. sd_girth = 1.31
  10.  
  11. # Correlation between erect girth and bone-pressed erect length
  12. corr = 0.55 #https://sci-hub.se/10.1111/jsm.12894
  13.  
  14. # Create Correlation Matrix
  15. cor_mat = np.array([[1, corr], [corr, 1]])
  16.  
  17. # Create standard deviation matrix
  18. std_mat = np.array([[sd_length**2, sd_length * sd_girth],
  19.                     [sd_length * sd_girth, sd_girth**2]])
  20.  
  21. # Create covariance matrix
  22. cov_mat = np.multiply(cor_mat, std_mat)
  23.  
  24. # Create mean matrix
  25. avg_mat = np.array([[mean_length], [mean_girth]])
  26.  
  27. # Calculate
  28. L = np.linalg.cholesky(cov_mat)
  29. X = np.random.normal(size=(2, 1_000_000)) #calculate 1MIL values
  30. Y = L.dot(X) + avg_mat
  31.  
  32. # Split into separate arrays
  33. lengths, girths = Y[0, :], Y[1, :]
  34.  
  35. # Calculate volumes
  36. volumes = 0.9 * lengths * np.pi * (girths / (2 * np.pi))**2
  37.  
  38. print(np.mean(volumes), np.std(volumes))
  39.  
  40. # Plot
  41. volumes = np.sort(volumes)
  42.  
  43. fig, axs = plt.subplots(1)
  44.  
  45. axs.hist(volumes, bins = 1000)
  46.  
  47. plt.show()
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement