I have used nls
function to fit the following equation
y ~ (C + (A1*exp(-x/h1)) + (A2*exp(-x/h2)))
My code looks as follows
f <- as.formula(y ~ (C + (A1*exp(-x/h1)) + (A2*exp(-x/h2))))
nls_b <- nls(f, data = df, start = list(C = 0.140, A1 = 0.051, h1 = 586.772, A2 = 0.166, h2 = 33.323))
summary(nls_b)
b_opt <- predict(nls_b, newdata=df)
Now I have plotted the model predicted values with the observed values against x as
plot(y=df$y, x=df$x)
lines(y=b_opt, x=df$x, type='l')
Now how can I have the following plot
Data
df = structure(list(x = c(2L, 5L, 10L, 33L, 50L, 100L, 500L, 1500L
), y = c(0.34272, 0.34256, 0.30483, 0.25772, 0.21584, 0.19295,
0.16144, 0.144)), class = "data.frame", row.names = c(NA, -8L
))
dput(df)
or a good chunk of it? – Allan Camerondput()
format. Please have a look at it. – Bappa Das