Conditions for a quadratic form to have a chi-squared distribution