Update app.py
Browse files
app.py
CHANGED
@@ -353,21 +353,24 @@ class RSM_BoxBehnken:
|
|
353 |
|
354 |
# ANOVA del modelo simplificado
|
355 |
anova_table = sm.stats.anova_lm(self.model_simplified, typ=2)
|
356 |
-
|
357 |
-
#
|
358 |
ss_total = anova_table['sum_sq'].sum()
|
359 |
-
|
360 |
# Crear tabla de contribuci贸n
|
361 |
contribution_table = pd.DataFrame({
|
362 |
-
'
|
363 |
'Suma de Cuadrados': [],
|
364 |
-
'
|
|
|
|
|
|
|
365 |
'% Contribuci贸n': []
|
366 |
})
|
367 |
-
|
368 |
# Calcular estad铆sticos F y porcentaje de contribuci贸n para cada factor
|
369 |
ms_error = anova_table.loc['Residual', 'sum_sq'] / anova_table.loc['Residual', 'df']
|
370 |
-
|
371 |
for index, row in anova_table.iterrows():
|
372 |
if index != 'Residual':
|
373 |
factor_name = index
|
@@ -377,17 +380,38 @@ class RSM_BoxBehnken:
|
|
377 |
factor_name = f'{self.x2_name}^2'
|
378 |
elif factor_name == f'I({self.x3_name} ** 2)':
|
379 |
factor_name = f'{self.x3_name}^2'
|
380 |
-
|
381 |
ss_factor = row['sum_sq']
|
382 |
-
|
|
|
|
|
|
|
383 |
contribution_percentage = (ss_factor / ss_total) * 100
|
384 |
|
385 |
contribution_table = pd.concat([contribution_table, pd.DataFrame({
|
386 |
-
'
|
387 |
'Suma de Cuadrados': [ss_factor],
|
388 |
-
'
|
|
|
|
|
|
|
389 |
'% Contribuci贸n': [contribution_percentage]
|
390 |
})], ignore_index=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
|
392 |
return contribution_table.round(3)
|
393 |
|
|
|
353 |
|
354 |
# ANOVA del modelo simplificado
|
355 |
anova_table = sm.stats.anova_lm(self.model_simplified, typ=2)
|
356 |
+
|
357 |
+
# Suma de cuadrados total
|
358 |
ss_total = anova_table['sum_sq'].sum()
|
359 |
+
|
360 |
# Crear tabla de contribuci贸n
|
361 |
contribution_table = pd.DataFrame({
|
362 |
+
'Fuente de Variaci贸n': [],
|
363 |
'Suma de Cuadrados': [],
|
364 |
+
'Grados de Libertad': [],
|
365 |
+
'Cuadrado Medio': [],
|
366 |
+
'F': [],
|
367 |
+
'Valor p': [],
|
368 |
'% Contribuci贸n': []
|
369 |
})
|
370 |
+
|
371 |
# Calcular estad铆sticos F y porcentaje de contribuci贸n para cada factor
|
372 |
ms_error = anova_table.loc['Residual', 'sum_sq'] / anova_table.loc['Residual', 'df']
|
373 |
+
|
374 |
for index, row in anova_table.iterrows():
|
375 |
if index != 'Residual':
|
376 |
factor_name = index
|
|
|
380 |
factor_name = f'{self.x2_name}^2'
|
381 |
elif factor_name == f'I({self.x3_name} ** 2)':
|
382 |
factor_name = f'{self.x3_name}^2'
|
383 |
+
|
384 |
ss_factor = row['sum_sq']
|
385 |
+
df_factor = row['df']
|
386 |
+
ms_factor = ss_factor / df_factor
|
387 |
+
f_stat = ms_factor / ms_error
|
388 |
+
p_value = f.sf(f_stat, df_factor, anova_table.loc['Residual', 'df'])
|
389 |
contribution_percentage = (ss_factor / ss_total) * 100
|
390 |
|
391 |
contribution_table = pd.concat([contribution_table, pd.DataFrame({
|
392 |
+
'Fuente de Variaci贸n': [factor_name],
|
393 |
'Suma de Cuadrados': [ss_factor],
|
394 |
+
'Grados de Libertad': [df_factor],
|
395 |
+
'Cuadrado Medio': [ms_factor],
|
396 |
+
'F': [f_stat],
|
397 |
+
'Valor p': [p_value],
|
398 |
'% Contribuci贸n': [contribution_percentage]
|
399 |
})], ignore_index=True)
|
400 |
+
|
401 |
+
# Calcular estad铆stico F global y su valor p
|
402 |
+
f_global = anova_table['sum_sq'][:-1].sum() / anova_table['df'][:-1].sum() / ms_error
|
403 |
+
p_global = f.sf(f_global, anova_table['df'][:-1].sum(), anova_table.loc['Residual', 'df'])
|
404 |
+
|
405 |
+
# Agregar fila para el estad铆stico F global
|
406 |
+
contribution_table = pd.concat([contribution_table, pd.DataFrame({
|
407 |
+
'Fuente de Variaci贸n': ['F global'],
|
408 |
+
'Suma de Cuadrados': [np.nan],
|
409 |
+
'Grados de Libertad': [np.nan],
|
410 |
+
'Cuadrado Medio': [np.nan],
|
411 |
+
'F': [f_global],
|
412 |
+
'Valor p': [p_global],
|
413 |
+
'% Contribuci贸n': [np.nan]
|
414 |
+
})], ignore_index=True)
|
415 |
|
416 |
return contribution_table.round(3)
|
417 |
|