2
2
import pandas as pd
3
3
import plotly .express as px
4
4
import scipy .stats as stats
5
+ import pingouin as pg
5
6
6
7
7
8
@st .cache_data
8
- def test_equal_variance (attribute , between ):
9
+ def test_equal_variance (attribute , between , correction ):
9
10
# test for equal variance
10
11
data = pd .concat ([st .session_state .data , st .session_state .md ], axis = 1 )
11
12
variance = pd .DataFrame (
12
13
{
13
- f"{ between [0 ]} - { between [1 ]} " : [
14
+ f"{ between [0 ]} - { between [1 ]} " : pg . multicomp ( [
14
15
stats .levene (
15
16
data .loc [
16
17
(data [attribute ] == between [0 ]),
@@ -22,19 +23,19 @@ def test_equal_variance(attribute, between):
22
23
],
23
24
)[1 ]
24
25
for f in st .session_state .data .columns
25
- ]
26
+ ], method = correction )[ 1 ]
26
27
}
27
28
)
28
29
fig = px .histogram (
29
30
variance ,
30
- nbins = 100 ,
31
+ nbins = 20 ,
31
32
template = "plotly_white" ,
33
+ range_x = [- 0.025 , 1.025 ],
32
34
)
33
- fig .update_traces (marker_color = "#696880" )
34
35
fig .update_layout (
35
36
bargap = 0.2 ,
36
37
font = {"color" : "grey" , "size" : 12 , "family" : "Sans" },
37
- title = {"text" : f"TEST FOR EQUAL VARIANCE" , "font_color" : "#3E3D53" },
38
+ title = {"text" : f"TEST FOR EQUAL VARIANCE (LEVENE) " , "font_color" : "#3E3D53" },
38
39
xaxis_title = "p-value" ,
39
40
yaxis_title = "count" ,
40
41
showlegend = False
@@ -43,7 +44,7 @@ def test_equal_variance(attribute, between):
43
44
44
45
45
46
@st .cache_data
46
- def test_normal_distribution (attribute , between ):
47
+ def test_normal_distribution (attribute , between , correction ):
47
48
# test for normal distribution
48
49
data = pd .concat ([st .session_state .data , st .session_state .md ], axis = 1 )
49
50
for b in between :
@@ -52,34 +53,33 @@ def test_normal_distribution(attribute, between):
52
53
return None
53
54
normality = pd .DataFrame (
54
55
{
55
- f"{ b } " : [
56
+ f"{ b } " : pg . multicomp ( [
56
57
stats .shapiro (
57
58
data .loc [
58
- (data [attribute ] == between [ 0 ] ),
59
+ (data [attribute ] == b ),
59
60
f ,
60
61
]
61
62
)[1 ]
62
63
for f in st .session_state .data .columns
63
- ]
64
+ ], method = correction )[ 1 ]
64
65
for b in between
65
66
}
66
67
)
67
68
68
69
fig = px .histogram (
69
- normality . iloc [:, 1 ] ,
70
- nbins = 100 ,
70
+ normality ,
71
+ nbins = 20 ,
71
72
template = "plotly_white" ,
72
- color_discrete_sequence = [ "#696880" , "#ef553b" ],
73
- opacity = 0.8 ,
73
+ range_x = [ - 0.025 , 1.025 ],
74
+ barmode = "group" ,
74
75
)
75
- fig .update_traces (marker_color = "#696880" )
76
76
77
77
fig .update_layout (
78
78
bargap = 0.2 ,
79
79
font = {"color" : "grey" , "size" : 12 , "family" : "Sans" },
80
- title = {"text" : f"TEST FOR NORMALITY" , "font_color" : "#3E3D53" },
80
+ title = {"text" : f"TEST FOR NORMALITY (SHAPIRO-WILK) " , "font_color" : "#3E3D53" },
81
81
xaxis_title = "p-value" ,
82
82
yaxis_title = "count" ,
83
- showlegend = False
83
+ showlegend = True
84
84
)
85
85
return fig
0 commit comments