# Given weighted mean and raw data, derive weights to minimize error

Imagine I have a set of data from an experiment:
Observed Measurement 1: 5
Observed Measurement 2: 6
Observed Measurement 3: 7
Observed Measurement 4: 8
Observed Measurement 5: 9

I have a target mean of 6--I need to choose a set of weights that map the observational data to the target mean.

What's the general process for deriving the weights of each measurement in the desired weighted mean? Obviously for one set of data there are infinitely many weight possibilities (particularly if there are no bounds for he possible weights), but say I had 10 sets of data, each of which used the same weights---Weight 1 is always used on the first measurement, weight 2 is always used on the second measurement, etc-and say I wanted to minimize the use of weighting by getting each weight as close to 1.0 as possible.

I have a large-n number of measurement,mean sets, well over 100, and I want to use the same weight for each and get the closest results possible.

It's been a number of years since I've done any kind of statistics and I'm thinking there has to be some sort of line of best fit, least-squares, or something? If it's a process that I can automate into a little python script, more's the better.

My day job mostly involves qualitative stuff these days, not quantitative, but I do have some background in math.

## 1 Answer

It looks like you could use linear regression (without an intercept). Each dataset could be used as one "observation, and for each of those, the observed measurements are the covariates and the target mean is the outcome of interest.

That way, you would fit a model like: $$E[target] = \beta_1 obsmeas_1 + \beta_2 obsmeas2 + ...$$

An ordinary least squares fit for this would indeed minimize the error in the sense that you require, because the predictions of the model would indeed be the weighted averages, and OLS minimizes the distances between these predictions and the actual outcome (here: your target means).

Caveat: this includes no way of enforcing all your weights to be positive. I'm guessing this can be done through some penalization, but I don't see it immediately.