[R] Error using nls function

J C Nash pro|jcn@@h @end|ng |rom gm@||@com
Sat Mar 27 21:03:14 CET 2021


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
>



More information about the R-help mailing list