chisq: mathematical background