Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take into account weights when using weighted linear or nonlinear least squares #38

Open
tomwenseleers opened this issue Mar 28, 2018 · 2 comments

Comments

@tomwenseleers
Copy link

The help file of investr seems to indicate that weights are ignored when using weighted linear (lm) or nonlinear least squares analysis (nls). Would it be hard to take into account weights, e.g. if one uses weights to deal with heteroscedastic errors? I understand that this should be straightforward, right, looking at
https://stats.stackexchange.com/questions/175127/prediction-intervals-with-heteroscedasticity
and
http://weightinginbayesianmodels.github.io/poctcalibration/over_tutorials.html
http://weightinginbayesianmodels.github.io/poctcalibration/calib_tut4_curve_ocon.html
http://weightinginbayesianmodels.github.io/poctcalibration/calib_tut5_precision_ocon.html
http://weightinginbayesianmodels.github.io/poctcalibration/AMfunctions.html#sdXhat ?
Would it require a big change in the code to take into account weights (in my case I was using a model where variance was a power function of the mean, resulting in weights = 1/variance = 1/(fitted vals^power in an nls model)?

@tomwenseleers
Copy link
Author

Just realise that probably the easiest way to support weights in lm's or nls models would be to multiply both the dependent variable and each of the predictors with the sqrt(weights) if weights are given, since weighted least squares minimizes sum( w * (Y - X %% beta)^2 ) = sum_i( (sqrt(w[i]) * X[i, ] %% beta - sqrt(w[i]) * Y[i])^2 )

@bgreenwell
Copy link
Owner

Right, the weights argument is currently ignored, but I will try to work on this as well once the semester ends in a couple of weeks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants