dfs-with-r / coach

Lineup optimization for daily fantasy sports
https://dfs-with-r.github.io/coach/
GNU General Public License v3.0
46 stars 14 forks source link

randomness? #22

Closed Sofaism closed 3 years ago

Sofaism commented 4 years ago

Hi thanks for work you've done on this! Just wondering if there is way to do dnorm(I think this would be correct one) instead of rnorm to keep randomness tighter and closer to our projections? and allow us to adjust range based on projection?

So if projection is like 50, we can say 10% and range stays between 45-55, but most of random numbers will be really tight around ~50

zamorarr commented 4 years ago

Hi @Sofaism

Thanks for using the package. Both rnorm() and dnorm() are functions related to the Normal distribution. The difference is that rnorm() returns random numbers from that distribution and dnorm() returns probability density values. Since we need a function to generate random values from, I think we need rnorm().

For what you are trying to do I think you can accomplish this by making the standard deviation smaller in rnorm() to get a tighter distribution of numbers. In the README I used a value of 10 but you should reduce that smaller to something like 2. For example:

n <- nrow(data)
randomness <- function(x) rnorm(n, x, 2)
optimize_generic(data, model, L = 5, randomness = randomness)

However if you are trying to make it so that the standard deviation is a percentage of the mean (say 5%), instead of an absolute value you can use a function like this:

n <- nrow(data)
randomness <- function(x) rnorm(n, x, 0.05*x)
optimize_generic(data, model, L = 5, randomness = randomness)

I would also suggest plotting a histogram of random values with 10,000 samples while you are picking a value for the standard deviation to see that it matches your intuition:

hist(rnorm(10000, 50, 0.05*50))

image

I hope that helps. Let me know if that answers your question.

Sofaism commented 4 years ago

Very cool thanks! One more question... If we had column with projected or average standard deviation for each player could we make function look at that number for each lineup optimization?
something like: randomness <- function(x) rnorm(n, x, data$stdev*x)

zamorarr commented 4 years ago

Yup I think that should work.

Sofaism commented 4 years ago

I get this: Error in FUN(X[[i]], ...) : not implemented In addition: Warning messages: 1: In rnorm(n, x, (data$std x)) : NAs produced 2: In rnorm(n, x, (data$std x)) : NAs produced

zamorarr commented 4 years ago

Hey @Sofaism, I can take a look. Can you provide a little more code so I can see what happened? What is in data$std? Are there any NAs in there?

zamorarr commented 3 years ago

I'll close this since this issue seems stale now. Feel free to re-open if the problem still occurs.