I am using the data from How can I get the coefficients from nlsList into a dataframe?
library(nlme)
dat<-read.table(text="time gluc starch solka
1 6.32 7.51 1.95
2 20.11 25.49 6.43
3 36.03 47.53 10.39
6 107.52 166.31 27.01
12 259.28 305.19 113.72
24 283.40 342.56 251.14
48 297.55 353.66 314.22", header = TRUE)
long <- tidyr::pivot_longer(dat, -1, values_to = "y")
long$name <- factor(long$name)
st0 <- list(Max = 200, k = 0.1, Lag = 0.5)
nlsList(y ~ (time > Lag) * Max * (1-exp(-k * (time - Lag))) | name,
long,
algorithm="port",
lower=c(k = 0.1, Max =-Inf, Lag = -Inf),
start = st0)
What I need differently is to not have k lower than 0.1, so I used algorithm="port", lower=c(k = 0.1, Max =-Inf, Lag = -Inf)
as in nls()
Prevent a nls-fit from falling below zero. It doesn't look like nlsList
is taking those 2 commands.
Error in nlsList(y ~ (time > Lag) * Max * (1-exp(-k * (time - Lag))) | name, :
unused arguments (algorithm = "port", lower=c(k = 0.1, Max =-Inf, Lag = -Inf))
How do I work around this issue?