# Method for ?not quite? weighted least squares fitting for more realistic results

I need a linear least squares type of fitting algorithm that understands how to weight the probability of a response coming from certain functions over another.
To explain, given the standard linear least squares problem: $$\textbf{Y} = \textbf{X} \mathbf{\beta} + \mathbf{\epsilon}$$

where $\textbf{Y}$ is the response vector, $\textbf{X}$ is the design matrix, $\beta$ is the solution vector, and $\epsilon$ is the residual vector - Is there a linear way to implement a 'weight' on a certain function (column) within the design matrix, such that this function (or set of functions) have a higher propensity to fit closer to the data than the other functions?

I have stumbled across weighted linear least squares, but that appears to assign higher propensity to fit certain sections of the response more accurately than the rest of the response via a diagonalized weight matrix (if I am looking at it right). I believe my problem is different.

For instance, given a $\textbf{Y}$ of experimental data such as this: with one function (column) of the design matrix such as this in red: and other functions which make up the design matrix with much larger derivatives (incommensurate with that of the spectral response of $\textbf{Y}$): We may end up getting a better linear fit by choosing non zero values for the several small spectral responses over the one larger one, which may make more physical sense (although there has been some error in calculating where the mean is). So we end up with a choice of the red or orange lines given here: Is there a way of making sure that the spectral responses ahve similar underlying profiles, or that small derivative functions prevail in fitting where the experimental data has a small derivative itself?

It looks like your first fit is trying to fit all the data to a single spectral line. The problem is the bumps in your data around $6.5$ and $15$. Depending on how you assess the probable error on each point, those bumps are going to pull your fit very hard. This is especially true if you take the error to be something like the square root of the expected number of counts in the bin. I am surprised to see the line shifted that far to the right. I would have expected it to be better centered, but broader than it should be. You might have an error that adds $1$ to the $x$ value in your fitted equation. I would suggest you try fitting some cleaner data and see if it fits properly.
On siemple fix would be to only fit the data from $7$ to $14$. The outside bumps might be noise. Another fix would be to fit your data to the sum of three spectral lines, letting the two new ones take care of the bumps. There may not be enough in the small bumps for this to work-you might get