2015-06-28 38 views
19

我如何计算Python中LOWESS回归的置信区间?我想将这些作为阴影区域添加到使用下面的代码创建的LOESS plot(其他软件包比statsmodels也好)。Python中LOWESS的置信区间

import numpy as np 
import pylab as plt 
import statsmodels.api as sm 

x = np.linspace(0,2*np.pi,100) 
y = np.sin(x) + np.random.random(100) * 0.2 
lowess = sm.nonparametric.lowess(y, x, frac=0.1) 

plt.plot(x, y, '+') 
plt.plot(lowess[:, 0], lowess[:, 1]) 
plt.show() 

我已经添加与来自webblog Serious Stats(它是使用ggplot创建在R)以下的置信区间的示例曲线图。

enter image description here

+0

statsmodels LOWESS不计算标准误差。 – user333700

+5

更好的理由提出这个问题...... – Thriveth

+0

这是一个更适合http://stats.stackexchange.com/的问题 –

回答

7

黄土不具有标准错误的明确概念。在这种情况下,这并不意味着什么。既然这样,你用坚强的方法坚持下去。

引导您的数据。您将要将LOESS曲线拟合到自举数据。看到这个页面的中间部分,你可以找到你所做的一些漂亮的照片。 http://statweb.stanford.edu/~susan/courses/s208/node20.html

enter image description here

一旦你有你大量不同的黄土曲线,你可以找到顶部和底部的X个百分点。

enter image description here