adding standard error to a predicted sigmoid using geom_line

Viewed 18

I have fitted a sigmoid to my data using the following code:

# fitting a sigmoid to the data
sig_fit <- nls2(amp~SSlogis(light_int,Asym,xmid,scal),data=data,
                weights=1/std_dev^2)
predx <- data.frame(light_int=10^seq(log10(min(data$light_int)),
                                    log10(max(data$light_int)), length.out=100))
predy <- data.frame(predx,amp=predict(sig_fit,predx), wts= TRUE)

# plot data amp
ggplot(data=data, aes(x= light_int, y= amp)) +
  geom_point(alpha= 0.25, size= 4, colour= '#00796b') +
  scale_x_log10(breaks= c(2.3e-6,2.3e-5, 2.3e-4, 2.3e-3, 2.3e-2), 
                labels=c('2.3e-6', '2.3e-5', '2.3e-4', '2.3e-3', '2.3e-2')) +
  labs(x= expression('stimulus intensity ('*mu~'mol /' ~ m^2~'s)'),
       y= 'peak amplitude (mV)') +
  geom_line(data=predy,size=1, colour= '#00796b')

and this is the output

fitted sigmoid for my data

Now, I would like to plot the standard deviations as in geom_smooth but I don't really know how to calculate them since the original data is 13 rows long and the predicted is 100. Thanks

0 Answers
Related