-
Notifications
You must be signed in to change notification settings - Fork 0
/
2a.py
69 lines (40 loc) · 1.29 KB
/
2a.py
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
from astropy.io import ascii
import scipy as sy
import matplotlib.pyplot as plt
from scipy.special import gammainc
data = ascii.read("datos.dat")
x=data["col1"]
y=data["col2"]
z=data["col3"]
sig=30*(10**(-6))
def param(y):
Y=sy.subtract(y,1)
A=[]
for m in x:
A.append([1,m,m**2,m**3,m**4,m**5])
theta= sy.dot( sy.linalg.inv(sy.dot( sy.transpose(A),A )) , sy.dot(sy.transpose(A),Y) )
return theta
theta=[-0.00113006 , 0.01220323 ,-0.04505635 , 0.07422477, -0.05635102 , 0.01623969 ]
grados=len(x)-len(theta)
datos=[]
for l in range(1000):
real=[]
for i in x:
e=sy.random.normal(0,sig)
real.append(1+theta[0] +theta[1]*i +theta[2]*(i**2) + theta[3]*(i**3) + theta[4]*(i**4)+ theta[5]*(i**5)+e)
pa=param(real)
modelo=[]
for i in x:
modelo.append(1+pa[0] +pa[1]*i +pa[2]*(i**2) + pa[3]*(i**3) + pa[4]*(i**4)+ pa[5]*(i**5) )
chi2=0
for h in range(len(x)):
chi2+= ((real[h]-modelo[h]) / (sig))**2
#print(chi2)
pvalue=1-gammainc(grados/2,chi2/2)
datos.append(pvalue)
#print(pvalue)
plt.figure("2")
n, bins, patches = plt.hist(datos, 20, facecolor='green', alpha=0.5)
plt.xlabel("p-value")
plt.ylabel("Cantidad")
plt.show()