[R] nls help
CharlieTheBrown77 at gmail.com
Wed Nov 30 21:41:22 CET 2011
Ah, I see, thank you both.
Michael Weylandt wrote
> It's a scaling problem:
> If you do this:
> datum <- datum[order(datum$X),]
> with(datum, plot(Y~X))
> with(datum, lines(X, 3400*exp(-1867*X)))
> you'll see that your initial guess is just so far gone that the nls()
> optimizer can't handle it.
> If you try a more reasonable initial guess it works fine:
> fit <- nls(Y ~ a*exp(-k * X), datum, start=c(a=3400, k=1.867))
> On Wed, Nov 30, 2011 at 12:14 PM, chuck.01 <CharlieTheBrown77@>
>> I have data like the following:
>> datum <- structure(list(Y = c(415.5, 3847.83333325, 1942.833333325,
>> 950.142857325, 2399.5833335, 804.75, 579.5, 841.708333325, 494.053571425
>> ), X = c(1.081818182, 0.492727273, 0.756363636, 0.896363636,
>> 1.518181818, 0.499166667, 1.354545455, 1.61, 1.706363636, 1.063636364
>> )), .Names = c("Y", "X"), row.names = c(NA, -10L), class = "data.frame")
>> with(datum, plot(Y~X))
>> As you can see there is a non-linear association between X and Y, and I
>> would like to fit an appropriate model. I was thinking an exponential
>> model might work well.
>> I tried the following (a and k starting values are based off of a lm()
>> but get an error.
>> fit <- nls(Y ~ a*exp(-k * X), datum, start=c(a=3400, k=1867))
>> Error in nlsModel(formula, mf, start, wts) :
>> singular gradient matrix at initial parameter estimates
>> I have never attempted to fit a non-linear model before, and thus the
>> may be inappropriately specified, or it is also possible that I have no
>> what I am doing.
>> Would someone please offer some advice.
>> View this message in context:
>> Sent from the R help mailing list archive at Nabble.com.
>> R-help@ mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
> R-help@ mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
View this message in context: http://r.789695.n4.nabble.com/nls-help-tp4123876p4124772.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help