bayesplain.regression¶
-
bayesplain.regression(x, y, prior=
'conventional', labels=None, unit='', reference=0.0, n_draws=None, seed='unset', data=None)[source]¶ Estimate how much
ychanges per unit ofx, with one predictor.- Parameters:¶
- x : array_like or str¶
Predictor and outcome, or the names of two columns in
data. Rows where either is missing are dropped, and the summary says how many.- y : array_like or str¶
Predictor and outcome, or the names of two columns in
data. Rows where either is missing are dropped, and the summary says how many.- prior : str, float, or EffectSizePrior, default 'conventional'¶
Cauchy prior on the standardised slope. Affects the Bayes factor only; the posterior and credible interval do not depend on it.
- labels : sequence of str, optional¶
Names of the predictor and the outcome, used in output.
- unit : str, optional¶
Unit of the slope, e.g.
"dollars per square foot".- reference : float, default 0.0¶
The slope to compare against. Zero means “no relationship”; set a policy-relevant value when one exists.
- n_draws : int, optional¶
Number of draws. Defaults to the package setting.
- seed : int or None, optional¶
Seed for the draws.
- data : data frame, optional¶
Where to look
xandyup when they are column names. The column names become the labels unlesslabelsis given.
- Returns:¶
Call
.summary(),.predict(x=...)for a forecast at a new value of the predictor, and.plot(kind='line')for the fitted line with its credible band.- Return type:¶
Examples
>>> import numpy as np, bayesplain as bp >>> rng = np.random.default_rng(0) >>> sqft = rng.uniform(800, 3000, 60) >>> value = 150 * sqft + rng.normal(0, 60_000, 60) >>> res = bp.regression(sqft, value, labels=["floor area", "assessed value"], ... unit="dollars per sq ft") >>> res.exact True >>> lo, hi = res.interval(kind="eti") >>> bool(np.allclose((lo, hi), res.frequentist.interval)) True