1. ## Weighted linear regression

Hello all,

I have a couple of questions regarding weighted linear regression that i will be using for the data analysis of my research work. I work in the area of Analytical chemistry, but i have to do a lot of data analysis stuff that includes linear regression (finding the best fit line and the corresponding slope, intercept etc.).Please share your opinions regarding my following questions.

1. Suppose i have an independent variable "X" and a dependent variable "Y". For different values of X and Y, I can obtain a best fit line in Microsoft Excel without using any weighting. How can i obtain a best fit line if i use a weighting scheme such as 1/x , 1/x/x , etc. ? Are there any free Statistical softwares available for drawing these best fit lines?

2. Also, in my research i will be having some baseline value of "Y" when X=0 (for example, for x=0, y = 10 units). In such a case, how is the weighting considered when x=0 ? I have this question because 1/x, 1/x/x cannot be defined when x=0 . How do these statistical softwares consider weighting in such a case? Will these softwares ignore the point (x,y) when x=0? What is the right thing to do in such a scenario?

Please provide information to the concerned questions.

Thanks,
Sai

2. edit deleted reply as it was incorrect

3. disclaimer: I made this up.

$y = a + bx + e$
y=dependant variable
x=independant variable
e=error

You want to minimise:
$f(x) = \sum{w_i e_i^{2}} = \sum{w_i(y_i-a_i-bx_i)^{2}}$
where $w_i$ is the weight applying to data point i.
(subscripts are dropped for the rest of this post)

Take derivatives with respect to a and set to 0
$\frac{\partial f}{\partial a} = -2 \sum{(yw - aw -bwx)} =0$

$\sum{(yw -bwx)} =a \sum{w}$

$\frac{\sum{(yw -bwx)}}{\sum{w}} =a$

Take derivatives with respect to b and set to 0
$\frac{\partial f}{\partial b} = -2 \sum{x(yw - aw -bwx)} =0$

$\sum{xyw} - \sum{awx} -\sum{bwx^{2}} =0$

$\sum{xyw} - a\sum{wx} -b\sum{wx^{2}} =0$

$\frac{\sum{xyw} - a\sum{wx}}{\sum{wx^{2}}} =b$

if you solve those simultaneously i think(!) you get

$b = \frac{\sum{w}\sum{xyw} - \sum{wx}\sum{wy}}{\sum{w}\sum{wx^{2}} - (\sum{wx})^{2}}$

$a = \frac{\sum{(yw -bwx)}}{\sum{w}}$

You can get the WLS fit line by solving those two equations simultaneously for a and b.

If you try to use a weighting of 1/x at x=0, you will get an undefined answer. You could choose a more suitable weighting function, manually set a very high weighting (eg 100000000000000) for x=0, or discard those data points.

Once again, i remind you that i made the above algebra up, and you should check it yourself!

4. google also suggests the following:

an excel implementation of WLS:
http://david.horner.faculty.noctrl.e...es_example.xls

a formula for WLS:
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 12, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7000433206558228, "perplexity": 703.9981769954553}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2017-13/segments/1490218190236.99/warc/CC-MAIN-20170322212950-00044-ip-10-233-31-227.ec2.internal.warc.gz"}