Skip to content
Permalink
Browse files

BUG: fix kernels smoothconf standard error, rename Biweight.smoothcon…

  • Loading branch information...
josef-pkt committed Dec 15, 2013
1 parent 30ce843 commit 29b90755a64f371048f5051c7390af4eacfcdd4f
Showing with 7 additions and 3 deletions.
  1. +7 −3 statsmodels/sandbox/nonparametric/kernels.py
@@ -219,23 +219,27 @@ def smoothvar(self, xs, ys, x):
else:
return np.nan

def smoothconf(self, xs, ys, x):
def smoothconf(self, xs, ys, x, alpha=0.05):
"""Returns the kernel smoothing estimate with confidence 1sigma bounds
"""
xs, ys = self.inDomain(xs, ys, x)

if len(xs) > 0:
fittedvals = np.array([self.smooth(xs, ys, xx) for xx in xs])
#fittedvals = self.smooth(xs, ys, x) # x or xs in Haerdle
sqresid = square(
subtract(ys, fittedvals)
)
w = np.sum(self((xs-x)/self.h))
#var = sqresid.sum() / (len(sqresid) - 0) # nonlocal var ? JP just trying
v = np.sum([rr*self((xx-x)/self.h) for xx, rr in zip(xs, sqresid)])
var = v / w
sd = np.sqrt(var)
K = self.L2Norm
yhat = self.smooth(xs, ys, x)
err = sd * K / np.sqrt(w * self.h * self.norm_const)
from scipy import stats
crit = stats.norm.isf(alpha / 2)
err = crit * sd * np.sqrt(K) / np.sqrt(w * self.h * self.norm_const)
return (yhat - err, yhat, yhat + err)
else:
return (np.nan, np.nan, np.nan)
@@ -337,7 +341,7 @@ def smoothvar(self, xs, ys, x):
else:
return np.nan

def smoothconf(self, xs, ys, x):
def smoothconf_(self, xs, ys, x):
"""Returns the kernel smoothing estimate with confidence 1sigma bounds
"""
xs, ys = self.inDomain(xs, ys, x)

0 comments on commit 29b9075

Please sign in to comment.
You can’t perform that action at this time.