Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

How can I get confidence intervals for an nls(broken stick) class object

$
0
0

I am trying to figure out how to obtain/plot confidence bounds for nls objects in R.

For example here is a nls model

bstick.lm.mean <- nls(TCTmean ~ cbind("intercept" = 1, 
                                      "l2Flow" = l2Flow, 
                                      "l2FlowBr" = ifelse(l2Flow > Br, 
                                                          l2Flow - Br, 0)),
                      start = list(Br = 6), 
                      algorithm = "plinear", 
                      data = flow.new.sum.dat)

So bstick.lm.mean is a nls class object.

new.seq4 = seq(min(flow.new.sum.dat$l2Flow), max(flow.new.sum.dat$l2Flow), length = 200)
new.seq4 = data.frame(new.seq4)
names(new.seq4) = 'l2Flow'

pz = predict(bstick.lm.mean, newdata = new.seq4, 
             interval = 'confidence', se.fit = TRUE, level = 0.95)
test.frame2 = data.frame(new.seq4,pz)

ggplot(data = test.frame2)+
  geom_point(mapping = aes(x = l2Flow, y = pz),
             shape = 1, col = 'red') +
  geom_point(data = test.frame,
             aes(x = l2Flow, y = TCTmean),
             shape = 0) +
  theme(panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.line = element_line(colour = "black")) +
  xlab("Log2 Flow (KL)") +
  ylab("Mean Transformed Ct")

Produces the following plot:

enter image description here

My question is, how can I obtain confidence bands for this non linear plot? I am reffering to the bands around the regression line.


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>