Dear S-plus Users,
I received three suggestions. Thanks to Marcel, Don MacKenzie and Peter ellis.
The solutions :
nls( ~sqrt(W) * (f(x)-x)), where W are the weights, and f(x) the nonlinear
function you want to fit.
Note:there is no weight argument in nls(). See Venables and Ripley for
a workaround (page 270 2nd edition)
Another suggestion is also stated below.
Thanks.
Abd Rahman Kassim
Hill Forest Silviculture
Forest Research Institute Malaysia (FRIM)
Kepong 52109
Kuala Lumpur
==========
I presume you want to fit a non-linear model because
you believe the response "bag" is normally distributed
before being put through the log transform. You can
have the effect of a non-linear model in this instance
by fitting a GLM (generalized linear model) with a
gaussian distribution and a log link, which I think is
equivalent to your nls model. S+ glm function does
not allow you to do this directly (only identity link
allowed with gaussian family), but the same effect can
be achieved by using a quasi-likelihood distribution
with variance = constant (ie the same mean to variance
relationship as a gaussian model). The code would be:
fit.glm <- glm(bag ~ bat + log(bat) + idp1 +
idp2,family=quasi(variance=constant, link=log),
weights=bat^w)
Of course, this is just a convenient work-around
because your model can be easily linearised.
My question was:
============
How can I write S-code for weighted nls using the
example shown below. I'm using the parameter estimates
from the linear regression for the nls function.
fit <- lm(log(bag) ~ bat + log(bat) + idp1 +
idp2,weights=bat^w)
b0 <- as.numeric(fit$coeff[1])
b1 <- as.numeric(fit$coeff[2])
b2 <- as.numeric(fit$coeff[3])
b3 <- as.numeric(fit$coeff[4])
b4 <- as.numeric(fit$coeff[5])
nls.st <- c(b0 , b1 , b2 , b3 , b4)
nls.fm <- nls(bag ~ exp(b0) * (exp(b1 * bat)) * (bat^
b2) * exp(b3 * idp1) * exp(b4 * idp2), start = ls.st,
trace = T)
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|