I have a data like that I want to fit decay.
library(tidyverse)
library(broom)
t = 1:100
x=1:80
y1=sample(seq(from = 20, to = 50), size = 100, replace = TRUE)
y1<-y1 %>% jitter()
y2 = 24 + (60 - 24) * -0.01 * x %>% jitter(10)
df1 <- tibble(t = t, y = y1, sensor = 'sensor1') %>%
rbind(. , data.frame(t = x, y = y2, sensor = 'sensor2'))
fit <- nls(y ~ SSasymp(t, yf, y0, log_alpha), data = sensor1)
fit
# Fit the data
fitted <- df %>%
nest(-sensor) %>%
mutate(
fit = map(data, ~nls(y ~ SSasymp(t, yf, y0, log_alpha), data = .)),
tidied = map(fit, tidy),
augmented = map(fit, augment),
)
And I got :
Error in mutate()
:
! Problem while computing fit = map(data, ~nls(y ~ SSasymp(t, yf, y0, log_alpha), data = .))
.
Caused by error in nls()
:
! singular gradient
Could you please let me where was the issue.