LOWESS在Python中的置信区间 [英] Confidence interval for LOWESS in Python

查看:305
本文介绍了LOWESS在Python中的置信区间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Python中计算LOWESS回归的置信区间?我想将它们作为阴影区域添加到使用以下代码创建的LOESS图中(除statsmodels之外的其他程序包也可以).

How would I calculate the confidence intervals for a LOWESS regression in Python? I would like to add these as a shaded region to the LOESS plot created with the following code (other packages than statsmodels are fine as well).

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中).

I've added an example plot with confidence interval below from the webblog Serious Stats (it is created using ggplot in R).

推荐答案

LOESS没有用于标准错误的明确概念.在这种情况下,它并不代表任何意义.既然这样,您就会陷入暴力破解的困境.

LOESS doesn't have an explicit concept for standard error. It just doesn't mean anything in this context. Since that's out, your stuck with the brute-force approach.

引导您的数据.您将使LOESS曲线适合自举数据.请参阅此页面的中间部分,以找到有关您所做工作的漂亮图片. http://statweb.stanford.edu/~susan/courses/s208/node20 .html

Bootstrap your data. Your going to fit a LOESS curve to the bootstrapped data. See the middle of this page to find a pretty picture of what your doing. http://statweb.stanford.edu/~susan/courses/s208/node20.html

一旦拥有大量不同的LOESS曲线,就可以找到顶部和底部Xth百分位数.

Once you have your large number of different LOESS curves, you can find the top and bottom Xth percentile.

这篇关于LOWESS在Python中的置信区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆