-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathANOVA_Example_Code.py
More file actions
109 lines (83 loc) · 3.88 KB
/
ANOVA_Example_Code.py
File metadata and controls
109 lines (83 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ANOVA Example Code
#
#created by Brian Joyce - Sandisk
#for PCISIG Devcon '26
#
#
import numpy as np
import pandas as pd
import scipy.stats
import matplotlib.pyplot as plt
import statsmodels.api as sm
from statsmodels.formula.api import ols
import math
# Create a default random number generator
# from a seed to get the same result every time
rng = np.random.default_rng(2)
#set the mean and stdev for the simulated results
mean=900
std=25
#generate a dataset of 3x fast, slow, nom processes, 3x low, nom, high voltage, and 3x low, nom, high temperature
data = {
'Process': ['nom']*27 + ['slow']*27 + ['fast']*27,
'Voltage': ['nom']*9 + ['low']*9 + ['high']*9 + ['low']*9 + ['nom']*9 + ['high']*9 + ['low']*9 + ['nom']*9 + ['high']*9,
'Temperature': ['nom']*3 + ['low']*3 + ['high']*3 + ['low']*3 + ['nom']*3 + ['high']*3 + ['low']*3 + ['nom']*3 + ['high']*3 + ['low']*3 + ['nom']*3 + ['high']*3 + ['low']*3 + ['nom']*3 + ['high']*3 + ['low']*3 + ['nom']*3 + ['high']*3 + ['low']*3 + ['nom']*3 + ['high']*3 + ['low']*3 + ['nom']*3 + ['high']*3 + ['low']*3 + ['nom']*3 + ['high']*3
}
mean=900
std=25
# temperature causes +/-25mV and voltage causes +/-10mV
Vtx_list = []
Case_list = []
for i in range(0, len(data['Process'])):
Vtx = rng.normal(loc=mean, scale=std)
if data['Voltage'][i] == 'low':
Vtx -= 10
elif data['Voltage'][i] == 'high':
Vtx += 10
if data['Temperature'][i] == 'low':
Vtx += 25
elif data['Temperature'][i] == 'high':
Vtx -= 25
Vtx_list.append(Vtx)
Case_list.append(data['Voltage'][i][0].upper()+"V"+data['Temperature'][i][0].upper()+"T")
data['Vtx'] = Vtx_list
data['Case'] = Case_list
#turn the data into a dataframe for analysis
df = pd.DataFrame(data)
#plot the different voltage/temperature cases
foo = df.boxplot(column='Vtx', by='Case', grid=False, rot=45, fontsize=10, figsize=(12,10), whis=(0, 100), showfliers=False)
plt.xlabel("voltage / temperature corner")
plt.ylabel("Vtx (mV)")
plt.suptitle("Traditional PVT analysis of Example ANOVA Vtx\n")
plt.title('Vtx normally distributed mean=900mV std=25mV \nVoltage Dependency+/-10mV Temperature Depedency +/-25mV', fontsize=8)
plt.show()
# Plot histogram of Vtx data with best fit normal distribution
from scipy.stats import norm
mean_vtx = df['Vtx'].mean()
std_vtx = df['Vtx'].std()
#create a model with the different levels for PVT
model = ols('Vtx ~ C(Process)+C(Voltage)+C(Temperature)', data=df).fit()
#run ANOVA on the model to get variance and significance
anova_table = sm.stats.anova_lm(model, typ=2)
print("\n"*3)
print(anova_table)
print(model.summary())
print("\n"*3)
meas_stdev = math.sqrt(anova_table['sum_sq']['Residual'] / anova_table['df']['Residual'])
# Calculate the mean Vtx for the case where Temperature is high and Voltage is low
meas_mean = model.params['Intercept'] + model.params["C(Voltage)[T.low]"]
print(f"ANOVA analysis of Vtx for high Temperature and low Voltage: {meas_mean}")
# Standard deviation is the square root of the mean squared error (MSE) from the ANOVA table
print(f"Standard deviation: {meas_stdev}")
# calculate the failure probability using the normal CDF and 800mV minimum limit
fail_prob = scipy.stats.norm(meas_mean, meas_stdev).cdf(800)
print(f"Failure probability: {fail_prob}")
print("\n"*3)
#just looking at the 3x slow, low, ect from a traditional analysis
print("Non-ANOVA analysis of the slow, low voltage, high temperature case")
std = df[(df['Process'] == "slow") & (df['Temperature'] == "high") & (df['Voltage'] == "low")]['Vtx'].std()
print(f"Standard deviation: {std}")
mean = df[(df['Process'] == "slow") & (df['Temperature'] == "high") & (df['Voltage'] == "low")]['Vtx'].mean()
print(f"Mean: {mean}")
min = df[(df['Process'] == "slow") & (df['Temperature'] == "high") & (df['Voltage'] == "low")]['Vtx'].min()
print(f"Min: {min}")