lessPython 0.2.0__py3-none-any.whl → 0.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lessPy/ANOVA.py +74 -15
- lessPy/Chart.py +431 -88
- lessPy/Correlation.py +40 -11
- lessPy/Flows.py +3 -3
- lessPy/Logit.py +15 -11
- lessPy/Regression.py +27 -21
- lessPy/X.py +280 -42
- lessPy/XY.py +1332 -239
- lessPy/__init__.py +12 -2
- lessPy/_themes.py +5007 -0
- lessPy/bc_items_plotly.py +33 -20
- lessPy/bc_plotly.py +27 -10
- lessPy/bubble_plotly.py +33 -17
- lessPy/corCFA.py +9 -5
- lessPy/corProp.py +8 -4
- lessPy/corReflect.py +8 -4
- lessPy/corReorder.py +8 -4
- lessPy/corScree.py +12 -8
- lessPy/data/StockPrice.csv +1401 -1386
- lessPy/details.py +17 -4
- lessPy/dn_plotly.py +74 -54
- lessPy/dot_plotly.py +9 -8
- lessPy/freq_poly_plotly.py +18 -11
- lessPy/getColors.py +247 -20
- lessPy/hier_plotly.py +41 -14
- lessPy/hs_plotly.py +23 -11
- lessPy/pie_plotly.py +1 -1
- lessPy/pivot.py +39 -9
- lessPy/plotly_utils.py +162 -29
- lessPy/plt_add.py +2 -7
- lessPy/plt_contour.py +6 -6
- lessPy/plt_contour_facet.py +3 -3
- lessPy/plt_mat_plotly.py +85 -12
- lessPy/plt_plotly.py +34 -18
- lessPy/plt_smooth.py +4 -4
- lessPy/plt_time.py +10 -3
- lessPy/prob_norm.py +7 -3
- lessPy/prob_tcut.py +7 -3
- lessPy/prob_znorm.py +7 -1
- lessPy/profile_plotly.py +5 -4
- lessPy/radar_plotly.py +4 -3
- lessPy/rcolors.py +461 -0
- lessPy/simCImean.py +7 -3
- lessPy/simCLT.py +7 -3
- lessPy/simFlips.py +7 -3
- lessPy/simMeans.py +7 -3
- lessPy/stats_out.py +257 -11
- lessPy/style.py +167 -0
- lessPy/sunflower_plotly.py +141 -0
- lessPy/ttest.py +17 -13
- lessPy/utils.py +146 -6
- lessPy/vbs_plotly.py +39 -27
- lessPy/x_console.py +763 -0
- {lesspython-0.2.0.dist-info → lesspython-0.3.1.dist-info}/METADATA +13 -2
- lesspython-0.3.1.dist-info/RECORD +89 -0
- {lesspython-0.2.0.dist-info → lesspython-0.3.1.dist-info}/WHEEL +1 -1
- lesspython-0.2.0.dist-info/RECORD +0 -84
- {lesspython-0.2.0.dist-info → lesspython-0.3.1.dist-info}/licenses/LICENSE +0 -0
- {lesspython-0.2.0.dist-info → lesspython-0.3.1.dist-info}/top_level.txt +0 -0
lessPy/Correlation.py
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import numpy as np
|
|
13
13
|
import pandas as pd
|
|
14
14
|
|
|
15
|
-
from .utils import fmt, get_column, get_option
|
|
15
|
+
from .utils import fmt, get_column, get_option, file_output, show_plots
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class CorrelationResults:
|
|
@@ -110,6 +110,7 @@ def _two_var(x, y, x_name, y_name, method, brief):
|
|
|
110
110
|
r, p = sps.pearsonr(xk, yk)
|
|
111
111
|
df = n - 2
|
|
112
112
|
t = r * np.sqrt(df / (1 - r ** 2))
|
|
113
|
+
stat_nm = "t"
|
|
113
114
|
p = 2 * sps.t.sf(abs(t), df)
|
|
114
115
|
z = np.arctanh(r)
|
|
115
116
|
sig = 1 / np.sqrt(n - 3)
|
|
@@ -119,17 +120,41 @@ def _two_var(x, y, x_name, y_name, method, brief):
|
|
|
119
120
|
sym, sym_pop = "r", "Correlation"
|
|
120
121
|
cov = float(np.cov(xk, yk)[0, 1])
|
|
121
122
|
elif method == "spearman":
|
|
123
|
+
# the statistic cor.test() reports: S, the sum of the squared
|
|
124
|
+
# rank differences, with no df. R analog: cr.main.R
|
|
125
|
+
# names(ct$statistic)
|
|
122
126
|
res = sps.spearmanr(xk, yk)
|
|
123
127
|
r, p = float(res.statistic), float(res.pvalue)
|
|
124
|
-
t, df =
|
|
125
|
-
(n - 2) / (1 - r ** 2)), n - 2
|
|
128
|
+
t, df, stat_nm = (n ** 3 - n) * (1 - r) / 6, None, "S"
|
|
126
129
|
method_txt = "Spearman's rank correlation rho"
|
|
127
130
|
sym = sym_pop = "rho"
|
|
128
131
|
else:
|
|
132
|
+
# cor.test(): T, the count of concordant pairs, with its exact
|
|
133
|
+
# p-value for n < 50 and no ties, else z with the variance
|
|
134
|
+
# corrected for ties
|
|
129
135
|
res = sps.kendalltau(xk, yk)
|
|
130
|
-
r
|
|
131
|
-
|
|
136
|
+
r = float(res.statistic)
|
|
137
|
+
_, xt = np.unique(xk, return_counts=True)
|
|
138
|
+
_, yt = np.unique(yk, return_counts=True)
|
|
139
|
+
ties = (xt > 1).any() or (yt > 1).any()
|
|
132
140
|
df = None
|
|
141
|
+
if n < 50 and not ties:
|
|
142
|
+
t, stat_nm = (r + 1) * n * (n - 1) / 4, "T"
|
|
143
|
+
p = float(sps.kendalltau(xk, yk, method="exact").pvalue)
|
|
144
|
+
else:
|
|
145
|
+
T0 = n * (n - 1) / 2
|
|
146
|
+
S = r * np.sqrt((T0 - (xt * (xt - 1)).sum() / 2)
|
|
147
|
+
* (T0 - (yt * (yt - 1)).sum() / 2))
|
|
148
|
+
v0 = n * (n - 1) * (2 * n + 5)
|
|
149
|
+
vt = (xt * (xt - 1) * (2 * xt + 5)).sum()
|
|
150
|
+
vu = (yt * (yt - 1) * (2 * yt + 5)).sum()
|
|
151
|
+
v1 = (xt * (xt - 1)).sum() * (yt * (yt - 1)).sum()
|
|
152
|
+
v2 = ((xt * (xt - 1) * (xt - 2)).sum()
|
|
153
|
+
* (yt * (yt - 1) * (yt - 2)).sum())
|
|
154
|
+
var_S = ((v0 - vt - vu) / 18 + v1 / (2 * n * (n - 1))
|
|
155
|
+
+ v2 / (9 * n * (n - 1) * (n - 2)))
|
|
156
|
+
t, stat_nm = S / np.sqrt(var_S), "z"
|
|
157
|
+
p = float(2 * sps.norm.sf(abs(t)))
|
|
133
158
|
method_txt = "Kendall's rank correlation tau"
|
|
134
159
|
sym = sym_pop = "tau"
|
|
135
160
|
|
|
@@ -152,9 +177,9 @@ def _two_var(x, y, x_name, y_name, method, brief):
|
|
|
152
177
|
else:
|
|
153
178
|
L.append(f"Sample Correlation: {sym} = {fmt(r, 3)}")
|
|
154
179
|
L.append("")
|
|
155
|
-
dfs = "
|
|
156
|
-
L.append(f"Hypothesis Test of 0 {sym_pop}:
|
|
157
|
-
f"
|
|
180
|
+
dfs = "" if df is None else f", df = {df}"
|
|
181
|
+
L.append(f"Hypothesis Test of 0 {sym_pop}: {stat_nm} = "
|
|
182
|
+
f"{fmt(t, 3)}{dfs}, p-value = {fmt(p, 3)}")
|
|
158
183
|
if method == "pearson":
|
|
159
184
|
L.append("95% Confidence Interval for Correlation: "
|
|
160
185
|
f"{fmt(lb, 3)} to {fmt(ub, 3)}")
|
|
@@ -222,13 +247,13 @@ def _matrix(df, miss, show, method, digits_d, heat_map, main):
|
|
|
222
247
|
if heat_map:
|
|
223
248
|
plots["heatmap"] = _heatmap(crs, main)
|
|
224
249
|
crs.attrs["plots"] = plots
|
|
225
|
-
return crs
|
|
250
|
+
return show_plots(crs)
|
|
226
251
|
|
|
227
252
|
|
|
228
253
|
def _heatmap(df, main):
|
|
229
254
|
import plotly.graph_objects as go
|
|
230
255
|
|
|
231
|
-
from .plotly_utils import plotly_style, to_hex
|
|
256
|
+
from .plotly_utils import as_plotly_color, plotly_style, to_hex
|
|
232
257
|
labels = list(df.columns)
|
|
233
258
|
Z = df.to_numpy(dtype=float).copy()
|
|
234
259
|
np.fill_diagonal(Z, np.nan)
|
|
@@ -239,9 +264,13 @@ def _heatmap(df, main):
|
|
|
239
264
|
colorbar=dict(title="r")))
|
|
240
265
|
fig.update_yaxes(autorange="reversed")
|
|
241
266
|
fig.update_layout(
|
|
242
|
-
template=None, paper_bgcolor=
|
|
267
|
+
template=None, paper_bgcolor=as_plotly_color(style["window_fill"]),
|
|
243
268
|
title=dict(text=main or "Correlations", x=0.5,
|
|
244
269
|
xanchor="center",
|
|
245
270
|
font=dict(size=round(
|
|
246
271
|
16 * get_option("main_size", 1)))))
|
|
247
272
|
return fig
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
# pdf_file= and png_file= write the figures, as lessR's pdf_file=
|
|
276
|
+
Correlation = file_output(Correlation)
|
lessPy/Flows.py
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import numpy as np
|
|
10
10
|
import pandas as pd
|
|
11
11
|
|
|
12
|
-
from .plotly_utils import BASE_COLORS, make_trans, to_hex
|
|
12
|
+
from .plotly_utils import as_plotly_color, BASE_COLORS, make_trans, to_hex
|
|
13
13
|
from .utils import get_column, get_option
|
|
14
14
|
|
|
15
15
|
|
|
@@ -96,7 +96,7 @@ def Flows(value, stage1, stage2, stage3=None, data=None,
|
|
|
96
96
|
node=dict(
|
|
97
97
|
label=nodes, color=node_color, x=node_x, y=node_y,
|
|
98
98
|
pad=12, thickness=16,
|
|
99
|
-
line=dict(color=
|
|
99
|
+
line=dict(color=as_plotly_color(border_gray), width=1),
|
|
100
100
|
hovertemplate="%{label}<extra></extra>"),
|
|
101
101
|
link=dict(
|
|
102
102
|
source=src, target=tgt, value=val, color=lcol,
|
|
@@ -116,5 +116,5 @@ def Flows(value, stage1, stage2, stage3=None, data=None,
|
|
|
116
116
|
r=30, b=30, l=30),
|
|
117
117
|
font=dict(size=round(15 * labels_size)),
|
|
118
118
|
template=None,
|
|
119
|
-
paper_bgcolor=
|
|
119
|
+
paper_bgcolor=as_plotly_color(get_option("window_fill", "white")))
|
|
120
120
|
return fig
|
lessPy/Logit.py
CHANGED
|
@@ -36,13 +36,13 @@ import pandas as pd
|
|
|
36
36
|
import plotly.graph_objects as go
|
|
37
37
|
|
|
38
38
|
from .plotly_utils import (
|
|
39
|
-
axis_format, axis_num, make_trans, plot_border,
|
|
39
|
+
as_plotly_color, axis_format, axis_num, make_trans, plot_border,
|
|
40
40
|
plotly_style, to_hex, x_grid)
|
|
41
41
|
from .plt_mat_plotly import scatter_matrix
|
|
42
42
|
from .logit_rmd import logit_rmd
|
|
43
43
|
from .Regression import (
|
|
44
44
|
_expand_indicators, _parse_formula, _prntbl)
|
|
45
|
-
from .utils import fmt, get_column, get_option, pretty
|
|
45
|
+
from .utils import fmt, get_column, get_option, pretty, file_output, show_plots
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
class LogitResults:
|
|
@@ -484,7 +484,7 @@ def Logit(my_formula, data=None, filter=None, ref_group=None,
|
|
|
484
484
|
list(data.columns), Rmd, Rmd_data, Rmd_format,
|
|
485
485
|
Rmd_browser, results, explain, interpret, code)
|
|
486
486
|
|
|
487
|
-
return out
|
|
487
|
+
return show_plots(out)
|
|
488
488
|
|
|
489
489
|
|
|
490
490
|
def _logit_confuse(lines, y01, fitv, pc, y_name, lv2_txt,
|
|
@@ -564,13 +564,13 @@ def _logit_plot(xv, y01, mu, levels, y_name, x_name, pc,
|
|
|
564
564
|
color=make_trans(pt_fill,
|
|
565
565
|
1 - transparency),
|
|
566
566
|
opacity=1,
|
|
567
|
-
line=dict(color=
|
|
567
|
+
line=dict(color=as_plotly_color(pt_fill),
|
|
568
568
|
width=1)),
|
|
569
569
|
hoverinfo="x+y", showlegend=False))
|
|
570
570
|
od = np.argsort(xv, kind="stable")
|
|
571
571
|
fig.add_trace(go.Scatter(
|
|
572
572
|
x=xv[od], y=mu[od], mode="lines",
|
|
573
|
-
line=dict(color=
|
|
573
|
+
line=dict(color=as_plotly_color(pt_fill), width=2),
|
|
574
574
|
hoverinfo="skip", showlegend=False))
|
|
575
575
|
axT1 = pretty(float(xv.min()), float(xv.max()))
|
|
576
576
|
axT2 = [0, 0.2, 0.4, 0.6, 0.8, 1]
|
|
@@ -579,7 +579,7 @@ def _logit_plot(xv, y01, mu, levels, y_name, x_name, pc,
|
|
|
579
579
|
ax_y = axis_num(y_lab, axT2,
|
|
580
580
|
[f"{v:g}" for v in axT2])
|
|
581
581
|
ax_y.update(range=[-0.10, 1.10], showgrid=True,
|
|
582
|
-
gridcolor=
|
|
582
|
+
gridcolor=as_plotly_color(style_opts["grid_col"]),
|
|
583
583
|
gridwidth=1, griddash="dot")
|
|
584
584
|
shapes = x_grid(axT1) + plot_border()
|
|
585
585
|
if pc is not None: # threshold crosshairs
|
|
@@ -588,13 +588,13 @@ def _logit_plot(xv, y01, mu, levels, y_name, x_name, pc,
|
|
|
588
588
|
shapes.append(dict(
|
|
589
589
|
type="line", xref="paper", yref="y",
|
|
590
590
|
x0=0, x1=1, y0=pc, y1=pc,
|
|
591
|
-
line=dict(color=
|
|
591
|
+
line=dict(color=as_plotly_color("gray35"), width=0.75,
|
|
592
592
|
dash="dash")))
|
|
593
593
|
if float(xv.min()) <= x_cut <= float(xv.max()):
|
|
594
594
|
shapes.append(dict(
|
|
595
595
|
type="line", xref="x", yref="paper",
|
|
596
596
|
x0=x_cut, x1=x_cut, y0=0, y1=1,
|
|
597
|
-
line=dict(color=
|
|
597
|
+
line=dict(color=as_plotly_color("gray35"), width=0.75,
|
|
598
598
|
dash="dash")))
|
|
599
599
|
anns = []
|
|
600
600
|
if levels is not None: # right-axis level labels
|
|
@@ -605,11 +605,15 @@ def _logit_plot(xv, y01, mu, levels, y_name, x_name, pc,
|
|
|
605
605
|
xanchor="left",
|
|
606
606
|
font=dict(size=round(
|
|
607
607
|
14 * get_option("axis_size", 0.9)),
|
|
608
|
-
color=
|
|
608
|
+
color=as_plotly_color(get_option(
|
|
609
609
|
"axis_color", "black")))))
|
|
610
610
|
fig.update_layout(
|
|
611
611
|
xaxis=ax_x, yaxis=ax_y, shapes=shapes,
|
|
612
612
|
annotations=anns, template=None,
|
|
613
|
-
plot_bgcolor=
|
|
614
|
-
paper_bgcolor=
|
|
613
|
+
plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
|
|
614
|
+
paper_bgcolor=as_plotly_color(style_opts["window_fill"]))
|
|
615
615
|
return fig
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
# pdf_file= and png_file= write the figures, as lessR's pdf_file=
|
|
619
|
+
Logit = file_output(Logit)
|
lessPy/Regression.py
CHANGED
|
@@ -31,8 +31,9 @@
|
|
|
31
31
|
# Numerics through statsmodels OLS (imported lazily, as
|
|
32
32
|
# plt_forecast does); influence measures from OLSInfluence.
|
|
33
33
|
# Returns a RegressionResults object holding the tables as
|
|
34
|
-
# DataFrames and the plotly figures in .plots
|
|
35
|
-
#
|
|
34
|
+
# DataFrames and the plotly figures in .plots. In a notebook the
|
|
35
|
+
# figures also display as the analysis runs, as lessR draws them;
|
|
36
|
+
# in a script they are not shown (utils.show_plots).
|
|
36
37
|
|
|
37
38
|
import math
|
|
38
39
|
import re
|
|
@@ -49,7 +50,8 @@ from .plotly_utils import (
|
|
|
49
50
|
BASE_COLORS, as_plotly_color, axis_format, axis_num,
|
|
50
51
|
make_trans, plot_border, plotly_style, to_hex, x_grid)
|
|
51
52
|
from .utils import (
|
|
52
|
-
category_order, fmt, get_column, get_option, pretty
|
|
53
|
+
category_order, fmt, get_column, get_option, pretty,
|
|
54
|
+
file_output, show_plots)
|
|
53
55
|
from .X import _breaks_from_args
|
|
54
56
|
|
|
55
57
|
|
|
@@ -1001,7 +1003,7 @@ def Regression(my_formula, data=None, filter=None, digits_d=None,
|
|
|
1001
1003
|
Rmd_browser, results, explain, interpret, code,
|
|
1002
1004
|
n_res_rows, n_pred_rows, res_sort, d)
|
|
1003
1005
|
|
|
1004
|
-
return out
|
|
1006
|
+
return show_plots(out)
|
|
1005
1007
|
|
|
1006
1008
|
|
|
1007
1009
|
def _reg_kfold(yv, Xd, y_name, pred_names, n_keep, formula,
|
|
@@ -1226,13 +1228,13 @@ def _moderation_plot(fit, Xd, y_name, mod_info, d):
|
|
|
1226
1228
|
ax_x = axis_num(x_name, axT1, axis_format(axT1, d))
|
|
1227
1229
|
ax_y = axis_num(y_name, axT2, axis_format(axT2, d))
|
|
1228
1230
|
ax_y.update(showgrid=True,
|
|
1229
|
-
gridcolor=
|
|
1231
|
+
gridcolor=as_plotly_color(style_opts["grid_col"]),
|
|
1230
1232
|
gridwidth=1, griddash="dot")
|
|
1231
1233
|
fig.update_layout(
|
|
1232
1234
|
xaxis=ax_x, yaxis=ax_y,
|
|
1233
1235
|
shapes=x_grid(axT1) + plot_border(), template=None,
|
|
1234
|
-
plot_bgcolor=
|
|
1235
|
-
paper_bgcolor=
|
|
1236
|
+
plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
|
|
1237
|
+
paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
|
|
1236
1238
|
legend=dict(title=dict(text=w_name)),
|
|
1237
1239
|
title=dict(text="Moderator Variable Interaction Plot",
|
|
1238
1240
|
x=0.5, xanchor="center",
|
|
@@ -1329,13 +1331,13 @@ def _reg_ancova_plot(fit, Xd, yv, y_name, info, d):
|
|
|
1329
1331
|
ax_x = axis_num(cov, axT1, axis_format(axT1, d))
|
|
1330
1332
|
ax_y = axis_num(y_name, axT2, axis_format(axT2, d))
|
|
1331
1333
|
ax_y.update(showgrid=True,
|
|
1332
|
-
gridcolor=
|
|
1334
|
+
gridcolor=as_plotly_color(style_opts["grid_col"]),
|
|
1333
1335
|
gridwidth=1, griddash="dot")
|
|
1334
1336
|
fig.update_layout(
|
|
1335
1337
|
xaxis=ax_x, yaxis=ax_y,
|
|
1336
1338
|
shapes=x_grid(axT1) + plot_border(), template=None,
|
|
1337
|
-
plot_bgcolor=
|
|
1338
|
-
paper_bgcolor=
|
|
1339
|
+
plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
|
|
1340
|
+
paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
|
|
1339
1341
|
legend=dict(title=dict(text=fac)),
|
|
1340
1342
|
title=dict(text="Scatterplot and Least-Squares Lines",
|
|
1341
1343
|
x=0.5, xanchor="center",
|
|
@@ -1382,11 +1384,11 @@ def _reg_scatter(xv, yv, x_name, y_name, fit, smapi, digits_d,
|
|
|
1382
1384
|
sizemode="diameter",
|
|
1383
1385
|
color=make_trans(pt_fill, 0.9),
|
|
1384
1386
|
opacity=1,
|
|
1385
|
-
line=dict(color=
|
|
1387
|
+
line=dict(color=as_plotly_color(pt_fill), width=1)),
|
|
1386
1388
|
hoverinfo="x+y", showlegend=False))
|
|
1387
1389
|
fig.add_trace(go.Scatter(
|
|
1388
1390
|
x=xs, y=sf["mean"].to_numpy(), mode="lines",
|
|
1389
|
-
line=dict(color=
|
|
1391
|
+
line=dict(color=as_plotly_color(get_option("fit_color",
|
|
1390
1392
|
"#5C4032")),
|
|
1391
1393
|
width=get_option("fit_lwd", 2)),
|
|
1392
1394
|
hoverinfo="skip", showlegend=False))
|
|
@@ -1403,7 +1405,7 @@ def _reg_scatter(xv, yv, x_name, y_name, fit, smapi, digits_d,
|
|
|
1403
1405
|
ax_y = axis_num(y_name, axT2,
|
|
1404
1406
|
axis_format(axT2, digits_d))
|
|
1405
1407
|
ax_y.update(showgrid=True,
|
|
1406
|
-
gridcolor=
|
|
1408
|
+
gridcolor=as_plotly_color(style_opts["grid_col"]),
|
|
1407
1409
|
gridwidth=1, griddash="dot")
|
|
1408
1410
|
title = ("Reg Line, Confidence & Prediction Intervals"
|
|
1409
1411
|
if with_bands
|
|
@@ -1411,8 +1413,8 @@ def _reg_scatter(xv, yv, x_name, y_name, fit, smapi, digits_d,
|
|
|
1411
1413
|
fig.update_layout(
|
|
1412
1414
|
xaxis=ax_x, yaxis=ax_y,
|
|
1413
1415
|
shapes=x_grid(axT1) + plot_border(), template=None,
|
|
1414
|
-
plot_bgcolor=
|
|
1415
|
-
paper_bgcolor=
|
|
1416
|
+
plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
|
|
1417
|
+
paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
|
|
1416
1418
|
title=dict(text=title, x=0.5, xanchor="center",
|
|
1417
1419
|
font=dict(size=round(
|
|
1418
1420
|
16 * get_option("main_size", 1)))))
|
|
@@ -1442,14 +1444,14 @@ def _reg_resfit(fitted, resid, cooks, cooks_cut, labels,
|
|
|
1442
1444
|
sizemode="diameter",
|
|
1443
1445
|
color=make_trans(pt_fill, 0.9),
|
|
1444
1446
|
opacity=1,
|
|
1445
|
-
line=dict(color=
|
|
1447
|
+
line=dict(color=as_plotly_color(pt_fill), width=0.5)),
|
|
1446
1448
|
hoverinfo="x+y", showlegend=False))
|
|
1447
1449
|
flag = np.where(cooks >= cut)[0]
|
|
1448
1450
|
for i in flag:
|
|
1449
1451
|
fig.add_annotation(
|
|
1450
1452
|
x=float(fitted[i]), y=float(resid[i]),
|
|
1451
1453
|
text=str(labels[i]), showarrow=False, yshift=12,
|
|
1452
|
-
font=dict(size=11, color=
|
|
1454
|
+
font=dict(size=11, color=as_plotly_color("gray30")))
|
|
1453
1455
|
axT1 = pretty(float(fitted.min()), float(fitted.max()))
|
|
1454
1456
|
axT2 = pretty(float(resid.min()), float(resid.max()))
|
|
1455
1457
|
ax_x = axis_num("Fitted Values", axT1,
|
|
@@ -1457,18 +1459,18 @@ def _reg_resfit(fitted, resid, cooks, cooks_cut, labels,
|
|
|
1457
1459
|
ax_y = axis_num("Residuals", axT2,
|
|
1458
1460
|
axis_format(axT2, digits_d))
|
|
1459
1461
|
ax_y.update(showgrid=True,
|
|
1460
|
-
gridcolor=
|
|
1462
|
+
gridcolor=as_plotly_color(style_opts["grid_col"]),
|
|
1461
1463
|
gridwidth=1, griddash="dot")
|
|
1462
1464
|
shapes = x_grid(axT1) + plot_border()
|
|
1463
1465
|
shapes.append(dict( # zero residual line
|
|
1464
1466
|
type="line", xref="paper", yref="y",
|
|
1465
1467
|
x0=0, x1=1, y0=0, y1=0,
|
|
1466
|
-
line=dict(color=
|
|
1468
|
+
line=dict(color=as_plotly_color("gray50"), width=1,
|
|
1467
1469
|
dash="dash")))
|
|
1468
1470
|
fig.update_layout(
|
|
1469
1471
|
xaxis=ax_x, yaxis=ax_y, shapes=shapes, template=None,
|
|
1470
|
-
plot_bgcolor=
|
|
1471
|
-
paper_bgcolor=
|
|
1472
|
+
plot_bgcolor=as_plotly_color(style_opts["panel_fill"]),
|
|
1473
|
+
paper_bgcolor=as_plotly_color(style_opts["window_fill"]),
|
|
1472
1474
|
title=dict(
|
|
1473
1475
|
text=("Residuals vs Fitted Values<br>"
|
|
1474
1476
|
f"<sup>{sub}</sup>"),
|
|
@@ -1489,3 +1491,7 @@ def _reg_dn_residual(resid):
|
|
|
1489
1491
|
show_histogram=True, hist_edges=edges,
|
|
1490
1492
|
main="Distribution of Residuals")
|
|
1491
1493
|
return fig
|
|
1494
|
+
|
|
1495
|
+
|
|
1496
|
+
# pdf_file= and png_file= write the figures, as lessR's pdf_file=
|
|
1497
|
+
Regression = file_output(Regression)
|