# Linear regression for samples of varying sizes

I have a data set of code patches and the bugs they produce. I'm using ordinary least squares to find a line which predicts bugs based on some attributes about the patch, such as the department which produced the code, how many issues were found in design, etc.

One thing is that the patches vary in size, and larger patches will (obviously) create more bugs. I'm trying to think of how I should handle this, and I came up with several options:

1. Use patch size (lines of code changed) as an independent variable. The problem with this is that I think I really want to predict defect "density". E.g. the Sales department might cause one bug every 15 lines of code, but the shipping people cause one every 30 lines of code. So I would need a variable like "department * lines of code changed", which I worry is more sensitive to overfitting.
2. Break it into samples of equal size. E.g. if a change to 10 lines of code caused 2 bugs, I pretend that this was actually 10 changes, each of which caused .2 bugs.
3. Divide through by the size and then weight by the size. i.e. minimize $\sum w_i(\frac{y_i}{w_i} - f(\vec{x_i}))^2$.

Are any of these preferable, or is there another option I should be using? I assume this must be a pretty standard problem to have, but I haven't been able to find anything online.

-
1) Ability to find (and introduce) bugs is an individual trait, having little to do with the department. 2) Code patches are supposed to fix bugs (unless the QA process is not working in your organization). 3) Why are your salesmen coding instead of selling products? –  Deer Hunter Dec 15 '12 at 16:15
Given that bugs is a count variable you probably shouldn't be using linear regression at all, but some form of count regression such as Poisson or negative binomial. –  Peter Flom Dec 15 '12 at 16:43
@Peter: Thank you, I have never heard of Poisson regression, but it sounds useful (Often bug creation modeled as Poisson distributed). I think I still have the problem of interaction between patch size and the other variables though, no? –  Xodarap Dec 15 '12 at 17:22
Yes, that problem is separate. –  Peter Flom Dec 15 '12 at 18:15
@DeerHunter: The dependent variable is bugs. Thank you for your comments about the experiment design, but I think a full explanation of what I'm doing goes outside the scope, and I would prefer to have an answer about the question I asked. –  Xodarap Dec 15 '12 at 20:05