Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

statsmodels - How to find the upper and lower CI values for new observation prediction using an ols model in Python? I want to plot those CI in a same plot

Like in R we can set the Confidence interval value as we want with a single line:

model = lm(formula = assay~time + batch,data = AssayData)
anova(model)
summary(model)
newdataB1 = data.frame("time" = seq(0,maxTime + 15,0.01),"batch" = factor(rep(1,length(seq(0,maxTime + 15,0.01)))))
pred1 = predict(object = model,newdata = newdataB1,interval = "confidence",level = 0.95)

Output look like: 
 pred1
         fit      lwr      upr time
1   98.32575 97.23913 99.41236 0.00
2   98.32638 97.24015 99.41261 0.01
3   98.32700 97.24116 99.41285 0.02
4   98.32763 97.24217 99.41309 0.03
5   98.32826 97.24319 99.41333 0.04
6   98.32889 97.24420 99.41358 0.05
7   98.32951 97.24521 99.41382 0.06
8   98.33014 97.24622 99.41406 0.07
9   98.33077 97.24723 99.41431 0.08
10  98.33140 97.24824 99.41455 0.09
11  98.33203 97.24926 99.41480 0.10
12  98.33265 97.25027 99.41504 0.11
13  98.33328 97.25128 99.41529 0.12
14  98.33391 97.25229 99.41553 0.13
15  98.33454 97.25330 99.41578 0.14
16  98.33516 97.25431 99.41602 0.15

The same thing I want to implement in python using statsmodels ols function. How to do it?

question from:https://stackoverflow.com/questions/66061030/how-to-find-the-upper-and-lower-ci-values-for-new-observation-prediction-using-a

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...