# Unable to figure out right transformation

I have obtained some data about how complexity of Java open source projects varies with time. I want to fit a curve to the data, however I am unable to figure out the right kind of transformation. I tried some that came immediately to my head: $\ 1/y \sim x,\ \log(y) \sim x,\ y \sim 1 + x + x^2$, etc. but I never got a good $R^2$ value.

Can you please suggest how do I proceed?

Below is the plot:

I have also shared the data here.

• How is project complexity measured? – Glen_b -Reinstate Monica Dec 5 '12 at 21:30
• You may be aiming for too high an $R^2$, the data has noise in it. Also, you say "time and complexity" but your graph has "lines of code" and "complexity" – Peter Flom - Reinstate Monica Dec 5 '12 at 21:36
• I think sharing the data has led to better comments and responses than would have been possible without it. – Glen_b -Reinstate Monica Dec 6 '12 at 0:25

y ~ log(x) results in a pretty good graph. I can think of a bunch of good reasons to use that. However, it's still hard to interpret without some more info on what complexity is here.

The data are noisy. You're not seeing that as well in your raw plots because the very steep initial slope hides a lot of noise in graphs like that. And it is pretty clear you have some heterogenous sources. If you can make them predictors as well you'll explain more of the data. As it is, the R2 with a log predictor is 0.54 and the QQ plot of residuals is great. Also, even a loess model with reasonable smoothing will only give you an R2 equivalent of about 0.58. That's a very small gain for a much more complex model (equivalent number of parameters 5).

First up: why is the value of $R^2$ important? If there's a certain level of noise in your data, you don't fix it (indeed, you can't), you measure it.

A loess smooth suggests that there's not an obvious simple functional relationship between mean scattering and log(LOC), though it does look as if monotonicity could be plausible:

Are there other predictors? Is there likely to be any serial dependence issues or other forms of substantive dependence?

Constant variance doesn't look tenable as an assumption; you might consider modelling both mean and variance (and perhaps something like AVAS - e.g. via the avas function in the ace package in R - might be relevant to you).

Edit: whuber makes some good points in the comment - you should certainly take that into account before jumping into something like AVAS.

• +1 Nice analysis. These data actually do look homoscedastic: you have to bear in mind that where log(LOC) is large, there is little data. The deceptive parts are the linear sequences of points: they probably reflect groups of closely related projects, indicating the points in this plot are not independent. – whuber Dec 5 '12 at 22:39
• Thanks for this valuable comment. I could buy the argument that it's homoskedastic in the low end (where the spread looks small, but it could be easily put down to less data). Looking at log(LOC) above about 13.5 (LOC above 730K), the spread looks substantially smaller to me over a fairly large fraction of x-space. It could be due to unmodelled positive dependence, but without further information I wouldn't want to just assume the variance was constant. In the meantime, substantial doubt about the behavior away from the middle third would be prudent. – Glen_b -Reinstate Monica Dec 6 '12 at 0:17