Tuesday, May 26, 2009

pDIF and obsession with polynomial fits

A recent thread on the BG forums about an investigation of "cRatio for two handers" really underscores the ignorance coming out of the "playerbase" that actively chooses to post on forums. To wit:
  • You got some motherfucker implying the "center" of advanced knowledge about game mechanics lay among those who were banned for Salvage duping, when the "center" is actually maybe 10 people at best, and not all are necessarily English-speaking, much less posters on BG.
  • Someone rightly points out that said motherfucker is some obsequious cock-gobbler (ok, those are my terms) since information on pDIF has been outdated since the "2-hander update" (well before the bannings) yet no one has actually bothered to do an honest investigation.
  • Another one actually bothers to collect some data on damage frequency to see what kind of distribution the data follows, but is easily derailed with a fetish for polynomial fitting to the data and data following a normal distribution (polynomial fitting and normality are contradictions as I will discuss soon).
This inexplicable obsession with polynomial fitting and normality is misguided for several reasons:
  • Normal distributions have obvious tails at the extremes. Moreover, the tails are neither too short nor too long. The data do not show evidence of any real tails.
  • Normal distributions are not parameterized by extrema (minimum and maximum). The parameters are the mean (center) and variance (spread).
  • A second-order polynomial fit cannot "account" for tails. This is obvious because normal distributions have inflection points. So you cannot use a polynomial fit and argue for "normality" at the same time.
  • Coefficient of determination can be thought of as a summary of a model fit. It doesn't mean the model is actually good. You can draw a squiggly line through all the data points and that will give you a R2 of 1, but that would be a terrible and useless model. Polynomial fitting is similarly terrible and useless for the above reasons.
  • Why even bother with any kind of fitting? As long as the distribution is symmetrical, at least you know the minimum, maximum, and median (same as mean) for pDIF given some value of cRatio, so you can use an expected value argument for long-run damage.
That said, there were some useful comments about the "shape" of the data. One poster actually suggested the data may follow some trapezoidal distribution. This is actually quite plausible under probability theory!

Obviously, the data do not appear to follow a uniform distribution. Even acknowledging the discreteness of damage (due to rounding) such that the minimum and maximum might be observed rarely, a uniform distribution of pDIF (NOT DAMAGE) is not all that likely. Although we cannot observe the uniform distribution of pDIF directly, we can observe histogram of damage (NOT pDIF). For this histogram, if pDIF were actually uniform, one might see an extreme "discontinuous" jump from the minimum to the minimum plus 1, or from the maximum to the maximum minus 1. In other words, the underlying true distribution of damage (NOT pDIF) would appear to be uniform except at the endpoints.

However, from probability theory, it is known that
  • The sum of two uniform random variables with the same variance (regardless of actual minimum and maximum) follows a triangular distribution
  • The sum of two uniform random variables with different variances follows a trapezoidal distribution (so a triangular distribution can be thought of as a degenerate trapezoidal distribution)
How can I argue that the underlying random component of melee damage could follow a trapezoidal distribution?
  • Does anyone actually expect the "developers" to have done anything particularly fancy with pDIF? In many cases, random number generation is basically "sampling" from a uniform distribution, usually Unif(0,1).
  • If pDIF does follow a uniform distribution (conditional on cRatio) for some ranges of cRatio (I realize this has been shown not to be the case for certain ranges of cRatio), there could easily be another random component to introduce "jitter" into the damage calculation, which would increase the variability of damage output yet keep the mean the same. This would account for the "1.05x correction" on maximum damage I've seen bandied about from time to time.
  • So, there could be an "effective" pDIF that includes jitter.
To illustrate the plausibility of the last two points, I simulated 9,885 realizations of non-critical melee damage given 55 "base damage," with pDIF that follows Unif(1, 1.8) and a "jitter" component that follows Unif(-0.1,0.1). Here, the random components are summed together so that the end result is that the fake data are trapezoidal. I plotted the frequencies and I also drew a nonsense curve through all the data points (in blue).


Yes, this is completely fake and is not meant to demonstrate the truth of anything, but merely the plausibility that pDIF follows (or has followed) a trapezoidal distribution for some values of cRatio. I even put in a second-order polynomial trend line, which has a very high coefficient of determination, which shows that R2 cannot say anything about whether the model is even appropriate. Here, we know it is grossly inappropriate because I know what the underlying probability model is.

Here's the R code for the simulation. Data were exported to Excel. And so goes an hour of my life.

N = 9885
a = trunc(55*(runif(N,min=1,max=1.8)+runif(N,min=-.1,max=.1)))
dmg = seq(min(a),max(a))
N2 = length(dmg)
dmg.counts = numeric(N2)

for (i in 1:N2) {
dmg.counts[i] = length(a[a==(i+min(a)-1)])
}