[R] Error using nls function
David E.S.
D@v|dE@tup|n@nS@nt@n@ @end|ng |rom hotm@||@com
Fri Mar 26 13:31:44 CET 2021
I'm trying to fit a harmonic equation to my data, but when I'm applying the
nls function, R gives me the following error:
Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at
initial parameter estimates.
All posts I've seen, related to this error, are of exponential functions,
where a linearization is used to fix this error, but in this case, I'm not
able to solve it in this way. I tried to use other starting points but it
still not working.
y <- c(20.91676, 20.65219, 20.39272, 20.58692, 21.64712, 23.30965, 23.35657,
24.22724, 24.83439, 24.34865, 23.13173, 21.96117)
t <- c(1, 2, 3, 4 , 5 , 6, 7, 8, 9, 10, 11, 12)
# Fitting function
fit <- function(x, a, b, c) {a+b*sin(2*pi*x)+c*cos(2*pi*x)}
res <- nls(y ~ fit(t, a, b, c), data=data.frame(t,y), start = list(a=1,b=0,
c=1))
Can you help me? Thanks!
David
--
Sent from: https://r.789695.n4.nabble.com/R-help-f789696.html
More information about the R-help
mailing list