1

I have a MySQL table with three columns: height, weight, gender. This table is being used as a model for my project. Is there a function of method in RoR that will allow me to calculate a normal distribution based on the data?

For example I would like to create a bell curve for men, and a bell curve for women, and then be able to determine the likelihood of any give height/weight value set as being male or female. New data will always be getting added, so the distributions will not be static.

Should I try to create a function in MySQL that creates the distributions, and then have a RoR method that evaluates input against the distribution, or can this all be done in RoR?

I am using Ruby 2.3 and rails 5.1.6.

Bad Programmer
  • 893
  • 1
  • 13
  • 27
  • 1
    I have not tried it, but [this gem](https://github.com/jtescher/descriptive-statistics) looks promising if your data is modest in size. If you are dealing with very large datasets, you will probably see performance gains with a database-centric solution. – moveson May 10 '18 at 21:22
  • What do you mean, "calculate a normal distribution based on the data"? I would be very surprised if height and weight follow a normal distribution. And, are you saying you want to calculate P(g|h,w)? I'm not sure you need distributions for that, but I haven't thought about it that hard. – jvillian May 10 '18 at 21:24
  • 1
    MySQL has a `STDDEV()` method. That sounds bell-curvy... – Phlip May 10 '18 at 21:34

1 Answers1

0

I made this more complicated than it needed to be. I used AVG() to get the mean and STDDEV() to get the standard deviation for each height and weight. I then added then subtracted the SD from the mean for the lower bound, and added the SD to the mean to the upper bound, and then evaluated first if the height was within one standard deviation of target, and then weight, and then used that to find probability.

Bad Programmer
  • 893
  • 1
  • 13
  • 27