Robert Brown FM CEFAS
2004-Nov-08 15:02 UTC
[R] Nonlinear weighted least squares estimation
Hi there, I'm trying to fit a growth curve to some data and need to use a weighted least squares estimator to account for heteroscedasticity in the data. A weights argument is available in nls that would appear to be appropriate for this purpose, but it is listed as 'not yet implemented'. Is there another package which could implement this procedure? Regards, Robert Brown
Hi Robert You can try gnls() in the nlme package or if that is not suitable, try to follow the example in the nls() help page for weighted regression that has an example of weighted regression from MASS. from the nls help page: ## weighted nonlinear regression Treated <- Puromycin[Puromycin$state == "treated", ] weighted.MM <- function(resp, conc, Vm, K) { ## Purpose: exactly as white book p.451 -- RHS for nls() ## Weighted version of Michaelis-Menten model ## ------------------------------------------------------------ ## Arguments: 'y', 'x' and the two parameters (see book) ## ------------------------------------------------------------ ## Author: Martin Maechler, Date: 23 Mar 2001, 18:48 pred <- (Vm * conc)/(K + conc) (resp - pred) / sqrt(pred) } Pur.wt <- nls( ~ weighted.MM(rate, conc, Vm, K), data = Treated, start = list(Vm = 200, K = 0.1), trace = TRUE) regards, Jesus -------------------------------------------------------------- Jes??s Mar??a Fr??as Celayeta School of Food Sci. and Env. Health. Faculty of Tourism and Food Dublin Institute of Technology Cathal Brugha St., Dublin 1. Ireland t +353 1 4024459 f +353 1 4024495 w www.dit.ie/DIT/tourismfood/science/staff/frias.html --------------------------------------------------------------> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Robert Brown FM > CEFAS > Sent: 08 November 2004 15:03 > To: r-help at stat.math.ethz.ch > Subject: [R] Nonlinear weighted least squares estimation > > > Hi there, > > I'm trying to fit a growth curve to some data and need to use a > weighted least squares estimator to account for > heteroscedasticity in the data. A weights argument is available > in nls that would appear to be appropriate for this purpose, but > it is listed as 'not yet implemented'. Is there another package > which could implement this procedure? > > Regards, > > Robert Brown > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > -- > This message has been scanned for content and > viruses by the DIT Information Services MailScanner > Service, and is believed to be clean. > http://www.dit.ie >-- This message has been scanned for content and viruses by the DIT Information Services MailScanner Service, and is believed to be clean. http://www.dit.ie
This question has been asked before on the list, but I'm not sure if the answer were posted. Basically, the trick is to write the formula a bit differently in nls() so that it does weighted least squares. nls() tries to minimize the sum of squared differences between the two sides of ~. If you write the formula as ~ sqrt(w) * (y - modelfun) where modelfun is the nonlinear function being fitted, you get the weighted nonlinear least squares solution. (Cf. page 241 of MASS4 and Section 10.3.3 of the White Book.) However, you need to watch out for predict(), etc., as their output corresponds to what you specify in the formula. HTH, Andy> From: Robert Brown FM CEFAS > > Hi there, > > I'm trying to fit a growth curve to some data and need to use > a weighted least squares estimator to account for > heteroscedasticity in the data. A weights argument is > available in nls that would appear to be appropriate for this > purpose, but it is listed as 'not yet implemented'. Is there > another package which could implement this procedure? > > Regards, > > Robert Brown > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >