Skip to content
Snippets Groups Projects
Commit 6b7ca4f7 authored by BOUANICH ANDREA's avatar BOUANICH ANDREA
Browse files

update normality test

parent 65e96534
No related branches found
No related tags found
No related merge requests found
...@@ -268,6 +268,7 @@ homosc_calcul, homosc_var, non_homos_var = quanti_homoscedasticity(df_quantitati ...@@ -268,6 +268,7 @@ homosc_calcul, homosc_var, non_homos_var = quanti_homoscedasticity(df_quantitati
config["thresholds_management"]["bartlett_threshold"]) config["thresholds_management"]["bartlett_threshold"])
normality_calcul, normal_var, non_normal_var =quanti_normality(df_quantitative,\ normality_calcul, normal_var, non_normal_var =quanti_normality(df_quantitative,\
config["variable_management"]["quantitative_variables"],\ config["variable_management"]["quantitative_variables"],\
config["variable_management"]["factor_variable"],\
config["thresholds_management"]["shapiro_threshold"]) config["thresholds_management"]["shapiro_threshold"])
var_anova = [] var_anova = []
for i in normal_var : for i in normal_var :
......
...@@ -683,7 +683,7 @@ def variable_weight(result): ...@@ -683,7 +683,7 @@ def variable_weight(result):
'contribution over&under mod' : ranking3}) 'contribution over&under mod' : ranking3})
return weight return weight
def quanti_normality(df,quanti_var, shapiro_pvalue): def quanti_normality(df,quanti_var,variable_cat,shapiro_pvalue):
""" """
Actions performed: Actions performed:
* Make the normality test on each quantitative variable * Make the normality test on each quantitative variable
...@@ -699,18 +699,35 @@ def quanti_normality(df,quanti_var, shapiro_pvalue): ...@@ -699,18 +699,35 @@ def quanti_normality(df,quanti_var, shapiro_pvalue):
List: a list containing the non normal variables List: a list containing the non normal variables
""" """
list_stat=[] list_stat=[]
list_variable = []
list_factor=[]
list_pvalue = [] list_pvalue = []
normal_variables=[] normal_variables=[]
non_normal_variables = [] non_normal_variables = []
factor_modalities = list(set(df[variable_cat].to_list()))
print(factor_modalities)
for variable in quanti_var : for variable in quanti_var :
stat, p_value = shapiro(df[variable]) count=0
list_stat.append(stat) for factor_modality in factor_modalities :
list_pvalue.append(p_value) list_variable.append(variable)
if p_value < shapiro_pvalue : list_factor.append(factor_modality)
non_normal_variables.append(variable) df_cat = df[df[variable_cat]==factor_modality]
stat, p_value = shapiro(df_cat[variable])
list_stat.append(round(stat,6))
if p_value < 0.000001 :
list_pvalue.append("<10-6")
else:
list_pvalue.append(round(p_value,6))
if p_value < shapiro_pvalue :
count = count
else :
count +=1
if count != len(factor_modalities) :
non_normal_variables.append(variable)
else: else:
normal_variables.append(variable) normal_variables.append(variable)
output_shapiro = pd.DataFrame({"variable":quanti_var,\ output_shapiro = pd.DataFrame({"variable":list_variable,\
"Factor modality":list_factor,\
"statistic":list_stat,\ "statistic":list_stat,\
"p-value":list_pvalue}) "p-value":list_pvalue})
return output_shapiro, normal_variables, non_normal_variables return output_shapiro, normal_variables, non_normal_variables
...@@ -738,8 +755,11 @@ def quanti_homoscedasticity(df,quanti_var, variable_cat,homoscedasticity_pvalue) ...@@ -738,8 +755,11 @@ def quanti_homoscedasticity(df,quanti_var, variable_cat,homoscedasticity_pvalue)
for var in quanti_var : for var in quanti_var :
df_cat = [df[df[variable_cat] == cat][var] for cat in df[variable_cat].unique()] df_cat = [df[df[variable_cat] == cat][var] for cat in df[variable_cat].unique()]
stat, p_value = bartlett(*df_cat) stat, p_value = bartlett(*df_cat)
list_stat.append(stat) list_stat.append(round(stat,6))
list_pvalue.append(p_value) if p_value < 0.000001 :
list_pvalue.append("<10-6")
else:
list_pvalue.append(round(p_value,6))
if p_value > homoscedasticity_pvalue : if p_value > homoscedasticity_pvalue :
homoscedasticity_variables.append(var) homoscedasticity_variables.append(var)
else : else :
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment