[R] Error using nls function
Mark Leeds
m@rk|eed@2 @end|ng |rom gm@||@com
Sat Mar 27 21:18:58 CET 2021
David: Note that your problem is linear so it looks like you can use the lm
function to estimate a, b and c. ( or as a check against what john
did ) Unless I'm missing something which could be the case !!!!! Also, see
Bloomfield's text for a closed form solution. I think it's
called "Intro To Fourier Analysis" or something of that nature.
On Sat, Mar 27, 2021 at 4:03 PM J C Nash <profjcnash using gmail.com> wrote:
> Use nlsr::nlxb() to get analytic derivatives. Though your problem is
> pretty rubbishy --
> look at the singular values. (You'll need to learn some details of nlxb()
> results to
> interpret.)
>
> Note to change the x to t in the formula.
>
> JN
>
> > f1 <- y ~ a+b*sin(2*pi*t)+c*cos(2*pi*t)
> > res1 <- nls(f1, data=data.frame(t,y), start=list(a=1,b=0, c=1))
> Error in nlsModel(formula, mf, start, wts) :
> singular gradient matrix at initial parameter estimates
> > library(nlsr)
> > res1n <- nlxb(f1, data=data.frame(t,y), start=list(a=1,b=0, c=1))
> > res1n
> nlsr object: x
> residual sumsquares = 28.644 on 12 observations
> after 3 Jacobian and 4 function evaluations
> name coeff SE tstat pval gradient
> JSingval
> a 11.2235 NA NA NA -2.473e-12
> 4.899
> b -1.55541e-09 NA NA NA 1.595e-14
> 8.399e-15
> c 11.2235 NA NA NA -2.473e-12
> 5.053e-16
> >
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list