# Dealing with grouped data in a reggression

Suppose I have the following database where I have, for each age, the average years of experience and income of the group and the number of individuals observed for such age (but not the income/experience of each individual):

----------------------------------------------------------------------------
| Average income | Age | Average years of experience | number of individuals
----------------------------------------------------------------------------
|     105.40     | 18  |            2.1              |          23
----------------------------------------------------------------------------
|     205.50     | 19  |            3.4              |          12
----------------------------------------------------------------------------
|     465.40     | 20  |            4.5              |          33
----------------------------------------------------------------------------
|     678.40     | 21  |            5.1              |          57
----------------------------------------------------------------------------
|     815.40     | 22  |            6.6              |          11
----------------------------------------------------------------------------
|     902.56     | 23  |            6.7              |          20
----------------------------------------------------------------------------
|     997.13     | 24  |            7.3              |          13


I want to get a regression [not necessarily a linear one] of the form:

$(Avg\_income) = \beta_0 + \beta_1 * (age) + \beta_2 * (Avg\_years\_xp)$

or

$(Income) = \beta_0 + \beta_1 * (age) + \beta_2 * (Years\_xp)$

The first approach I thought of was ignoring the "number of individuals" column and doing the regression as if I had only 7 observations, but this seems to be a waste of information, right?

The second was replicating each row by "number of individuals", but is this approach really correct? Also, I'd like to have this work in a more generalized way such that I can work a non-integer "number of individuals" (ok, doesn't make any sense in this example, but it does in my real problem).

Obs.: I'm planning doing a Bayesian inference, but Frequentist approaches are welcomed too. R syntax is good too.

• averages of more points will tend to be more precise. If the variance of individual observations is constant, the variance of averages will be proportional to $1/n_i$. You need to weight the averages so the more precise ones get more weight. – Glen_b Jan 31 '14 at 11:20
• @Glen_b thanks, do you know how one can use weights in other regression models like generalized linear models that don't have a variance parameter? (maybe this is subject to another question...) – random_user Feb 2 '14 at 23:59
• GLM functions will usually let you supply a vector of weights or some equivalent. – Glen_b Feb 3 '14 at 0:01