statspai.nonparametric¶
nonparametric ¶
Nonparametric estimation methods.
Provides local polynomial regression (lpoly), kernel density estimation (kdensity), and nonparametric regression (npregress).
LPolyResult ¶
Bases: ResultProtocolMixin
Results from local polynomial regression.
Examples:
>>> import statspai as sp
>>> import numpy as np, pandas as pd
>>> rng = np.random.default_rng(5)
>>> x = rng.uniform(0, 10, 300)
>>> y = np.sin(x) + rng.normal(0, 0.3, 300)
>>> df = pd.DataFrame({"y": y, "x": x})
>>> res = sp.lpoly(df, y="y", x="x", degree=1)
>>> type(res).__name__
'LPolyResult'
>>> res.degree
1
>>> bool(res.bandwidth > 0)
True
plot ¶
Plot the local polynomial fit with optional scatter and CI.
KDensityResult ¶
Bases: ResultProtocolMixin
Results from kernel density estimation.
Examples:
>>> import statspai as sp
>>> import numpy as np, pandas as pd
>>> rng = np.random.default_rng(3)
>>> df = pd.DataFrame({"income": rng.normal(10.0, 2.0, 500)})
>>> res = sp.kdensity(df, x="income", kernel="gaussian")
>>> type(res).__name__
'KDensityResult'
>>> bool(res.bandwidth > 0)
True
>>> bool((res.density >= 0).all())
True
plot ¶
Plot the kernel density estimate.