I want to do a simple lm of y~x where I weight my response variable. This is because the values of y are actually each in turn the value of a slope of another regression of y~year i.e. rates of change over time, and for each of these original regressions the number of recorded years was variable (some had data for 20 years, some for 40, some for 45 etc).

I realise weighting an lm has been discussed here:

How to use weights in function lm in R?

However I am unsure as to whether using the simple instructions outlined in this post I will be weighting y (which is what I want) or x, or whether the weight "acts" across the whole lm and the distinction I am drawing between weighting y specifically, rather than x, is invalid...

  • $\begingroup$ Let me know if any more specific info on the data is required... $\endgroup$ – Sarah Mar 5 '13 at 15:01
  • $\begingroup$ Could you clarify how exactly you want to "weight your response variable"? The weights parameter in lm() yields parameter estimates that minimize the weighted sum of squared residuals ("normal" OLS minimizes the unweighted sum), so high weight observations will be more influential in estimating the parameters. This actually sounds like just what you should be doing in your problem, but I probably am missing something. $\endgroup$ – Stephan Kolassa Mar 5 '13 at 17:01
  • $\begingroup$ Thanks for your comment. The values of the response variable I want to weight are slopes of regressions of change in date of an event with year, for each species in my dataset. The no. of recorded years for each species varies, thus the variance of the slopes that make up the y values are variable. I want to add greater weight to the y values that are more "reliable" (i.e. have a greater number of recorded years), so I was going to weight my y values by 1/var of the slope. My question was whether the weights function in R allows me to accomplish this, or if it is doing something different? $\endgroup$ – Sarah Mar 5 '13 at 17:15
  • $\begingroup$ This should be exactly what R does if you specify weights=1/slope.var. However, @AdamO points out a more appropriate method to deal with your question. $\endgroup$ – Stephan Kolassa Mar 6 '13 at 8:12

It may be important for you to understand the different types of multilevel modeling strategies out there before you resolve to this method. Your approach is not particularly common. In order to obtain a consistent and unbiased estimate of the slope of the slopes, you should use inverse variance weighting to account for slopes that are especially more variable. This is done easily in R by storing all your fits in a list of fits, then using the coef and vcov methods to extract the relevant information into an analyzable vector format.

  • $\begingroup$ Thanks Adam - inverse variance weighting was what I had planned to use so it's good to have confirmation that this is a good idea! $\endgroup$ – Sarah Mar 6 '13 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.