[R] nls question
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Jul 12 22:03:03 CEST 2012
On Thu, Jul 12, 2012 at 3:40 PM, Felipe Carrillo
<mazatlanmexico at yahoo.com> wrote:
> I get a different error now:
>> nls(weight ~ cbind(1, exp(gamma*week)), weightData, start = list(gamma=
>> 0.2), alg = "plinear")
> Error in nls(weight ~ cbind(1, exp(gamma * week)), weightData, start =
> list(gamma = 0.2), :
> step factor 0.000488281 reduced below 'minFactor' of 0.000976562
> The help file says: ........When start is missing, a very cheap guess for
> start is tried (if algorithm != "plinear").
Please give a reproducible example by setting the seed. This
reproducible example converges:
> set.seed(123)
> weight_random <- runif(50,1,24)
> weight <- sort(weight_random)
> weightData <- data.frame(weight,week=1:50)
> nls(weight ~ cbind(1, exp(gamma*week)), weightData, start = list(gamma = 0.2), alg = "plinear")
Nonlinear regression model
model: weight ~ cbind(1, exp(gamma * week))
data: weightData
gamma .lin1 .lin2
1.136e-03 -3.949e+02 3.962e+02
residual sum-of-squares: 9.17
Number of iterations to convergence: 8
Achieved convergence tolerance: 9.581e-06
as does nls with Gauss Newton:
> nls(weight ~ alpha + beta*exp(gamma*week), weightData, start =
+ c(alpha = 0.0, beta = 1, gamma = 0.2)
+ )
Nonlinear regression model
model: weight ~ alpha + beta * exp(gamma * week)
data: weightData
alpha beta gamma
-3.949e+02 3.961e+02 1.136e-03
residual sum-of-squares: 9.17
Number of iterations to convergence: 48
Achieved convergence tolerance: 2.906e-06
>
> So I removed 'plinear' from the call and got the following:
> nls(weight ~ cbind(1, exp(gamma*week)), weightData,start =
> list(gamma=0.2),trace=TRUE)
It cannot be specified as if it were a plinear model but then use
Gauss-Newton. See ?nls
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list