How could I plot the fitted model with the confident intervals for each predicted value (in x= 5, 10, 15, 20, 25, 30, 35) ?
For the next dataset
df<-data.frame(
x = rep(c( 5, 10, 15, 20, 25, 30, 35), each=4 ),
y = c(0.2, 1.1, 1.5, 0.9,
2.1, 1.9, 2.75, 3.4,
5.15, 4.6, 4.75, 4.15,
7, 6.7, 6.7, 6.95,
7, 5.45, 6.15, 6.4,
0.001, 0.001, 0.5,
0.001, 0.001, 0.001, 0.001, 0.001)
)
head(df)
And the follow fitted model:
fun <-with(df,
y ~ Yopt*((x-Tmin)/(Topt-Tmin))^(b1*(Topt-Tmin)/(Tmax-Topt))*((Tmax-x)/(Tmax-Topt))^b1
)
starters <- expand.grid(Yopt = seq(4, 8, len = 4),
Tmin = seq(0, 5, len = 4),
Topt = seq(15, 25, len = 4),
Tmax= seq(28, 38, len = 4),
b1 = seq(0, 4, len = 4))
fit <- nls2(fun, start = starters, algorithm = "brute-force")
summary(fit)
with(df, c(plot(y~x))); points(fitted(fit)~I(df$x), pch=19)
with(as.list(coef(fit)),
curve(
Yopt*((x-Tmin)/(Topt-Tmin))^(b1*(Topt-Tmin)/(Tmax-Topt))*((Tmax-x) / (Tmax-Topt)) ^ b1,
add=TRUE, col="red"))