Blame view

src/idl/dustem_chi2.pro 504 Bytes
52a3cc37   Annie Hughes   First commit of I...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
FUNCTION DUSTEM_CHI2, y, model, npar, err=err
; returns the chi-square value of fit MODEL to data Y
;
; NPAR (I): nr of parameters in the fit
; ERR  (I): error of each data point. Default is ERR=0.1*Y

  ny = n_elements(y)
  if n_elements(err) EQ 0 OR TOTAL(err) EQ 0 then begin
     err = 0.1*y
     print,'(W) CHI2: error missing, set to 10 %'
  endif
  ndof = ny - npar              ; nr of degrees of freedom
  chi = TOTAL( ((y-model)/err)^2 )
  if ndof GT 0 then chi = chi / ndof

  return, chi
END