Hi all,

I have two spectra with wavelength, flux, and error on flux. I want to find out 
the variability of these two spectra based on the 2 sample Chi-square test. 
I am using following code:

def compute_chi2_var(file1,file2,zemi,vmin,vmax):
    w1,f1,e1,c1,vel1 = get_spec_vel(dir_data+file1,zemi)
    id1 = np.where(np.logical_and(vel1 >= vmin, vel1 < vmax))[0]   
    w2,f2,e2,c2,vel2 = get_spec_vel(dir_data+file2,zemi)
    id2 = np.where(np.logical_and(vel2 >= vmin, vel2 < vmax))[0]
    f_int = interp1d(w1[id1], f1[id1]/c1[id1], kind='cubic')
    e_int = interp1d(w1[id1], e1[id1]/c1[id1], kind='cubic')  
    f_obs,e_obs  = f_int(w2[id2]), e_int(w2[id2]) 
    f_exp, e_exp = f2[id2]/c2[id2], e2[id2]/c2[id2]
    e_net = e_obs**2 + e_exp**2
    chi_square =  np.sum( (f_obs**2 -  f_exp**2)/e_net  )
    dof = len(f_obs) - 1
    pval = 1 - stats.chi2.cdf( chi_square, dof)
    print('%.10E' % pval)

NN = 320
compute_chi2_var(file7[NN],file14[NN],zemi[NN],vmin[NN],vmax[NN])

I am running this code on many files, and I want to grab those pair of spectra 
where, the p-value of chi-squa is less than 10^(-8),  for the change to be 
unlikely due to a random occurrence.
Is my code right concept-wise? Because the chi-squ value is coming out to be 
very large (positive and negative), such that my p-value is always between 1 
and 0 which I know from other's results not correct.

Can anyone suggest me is the concept of 2-sample chi-squ applied by me is 
correct or not?

I thank you all in advance.
 
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to