3
3
4
4
5
5
def ols (trendline_options , x_raw , x , y , x_label , y_label , non_missing ):
6
- """Ordinary Least Squares trendline function
6
+ """Ordinary Least Squares (OLS) trendline function
7
7
8
8
Requires `statsmodels` to be installed.
9
9
10
+ This trendline function causes fit results to be stored within the figure,
11
+ accessible via the `plotly.express.get_trendline_results` function. The fit results
12
+ are the output of the `statsmodels.api.OLS` function.
13
+
10
14
Valid keys for the `trendline_options` dict are:
11
15
12
- `add_constant` (`bool`, default `True`): if `False`, the trendline passes through
16
+ - `add_constant` (`bool`, default `True`): if `False`, the trendline passes through
13
17
the origin but if `True` a y-intercept is fitted.
14
18
15
- `log_x` and `log_y` (`bool`, default `False`): if `True` the OLS is computed with
19
+ - `log_x` and `log_y` (`bool`, default `False`): if `True` the OLS is computed with
16
20
respect to the base 10 logarithm of the input. Note that this means no zeros can
17
21
be present in the input.
18
22
"""
@@ -60,13 +64,14 @@ def ols(trendline_options, x_raw, x, y, x_label, y_label, non_missing):
60
64
61
65
62
66
def lowess (trendline_options , x_raw , x , y , x_label , y_label , non_missing ):
63
- """Locally Weighted Scatterplot Smoothing trendline function
67
+ """LOcally WEighted Scatterplot Smoothing (LOWESS) trendline function
64
68
65
69
Requires `statsmodels` to be installed.
66
70
67
71
Valid keys for the `trendline_options` dict are:
68
72
69
- `frac` (`float`, default `0.6666666`): the `frac` parameter from `statsmodels.api.nonparametric.lowess`
73
+ - `frac` (`float`, default `0.6666666`): the `frac` parameter from the
74
+ `statsmodels.api.nonparametric.lowess` function
70
75
"""
71
76
import statsmodels .api as sm
72
77
@@ -77,19 +82,25 @@ def lowess(trendline_options, x_raw, x, y, x_label, y_label, non_missing):
77
82
78
83
79
84
def ma (trendline_options , x_raw , x , y , x_label , y_label , non_missing ):
80
- """Moving Average trendline function
85
+ """Moving Average (MA) trendline function
86
+
87
+ Requires `pandas` to be installed.
81
88
82
- The `trendline_options` dict is passed as keyword arguments into the `pandas.Series.rolling` function.
89
+ The `trendline_options` dict is passed as keyword arguments into the
90
+ `pandas.Series.rolling` function.
83
91
"""
84
92
y_out = pd .Series (y , index = x_raw ).rolling (** trendline_options ).mean ()[non_missing ]
85
93
hover_header = "<b>MA trendline</b><br><br>"
86
94
return y_out , hover_header , None
87
95
88
96
89
97
def ewma (trendline_options , x_raw , x , y , x_label , y_label , non_missing ):
90
- """Exponentially Weighted Moving Average trendline function
98
+ """Exponentially Weighted Moving Average (EWMA) trendline function
99
+
100
+ Requires `pandas` to be installed.
91
101
92
- The `trendline_options` dict is passed as keyword arguments into the `pandas.Series.ewma` function.
102
+ The `trendline_options` dict is passed as keyword arguments into the
103
+ `pandas.Series.ewma` function.
93
104
"""
94
105
y_out = pd .Series (y , index = x_raw ).ewm (** trendline_options ).mean ()[non_missing ]
95
106
hover_header = "<b>EWMA trendline</b><br><br>"
0 commit comments