Is this way of calculating the chi-squared value correct? I have read that the chi-squared value is calculated as follows:
$$\chi^2 = \sum \frac{(\text{observed value} - \text{expected value})^2}{\text{(expected value)}}$$
However, this answer mentions it as:
$$\chi^2 = \sum \frac{(\text{observed value} - \text{true value})^2}{\text{(uncertainty associated with that observation)}^2}$$
Is it correct? Are the two equivalent? If so, how?
 A: There can be a lot of confusion about $\chi^2$ tests, as they appear in any application that involves sums of independent normally distributed random variables. The first version is the standard test for a contingency table or similar comparisons of known against expected values.
The second version seems to be an application of minimum chi-square estimation, compounded with a bit of confusion in the terminology. The "observed" values are those of a set of observations each with a different error estimate. In this application:

You numerically choose the "true value" that minimizes $\chi^2$. That's your best guess.

Thus each numerator term is related to an estimate of the variance of the observations about the (estimated, "true") mean.
Each denominator term, the square of the "uncertainty associated with that observation," is proportional to an estimate of the variance of the individual observation. So this procedure is equivalent to minimizing an inverse-variance-weighted mean-square error.
As best as I can tell, the further calculation of the $\chi^2$ statistic is to test whether the inverse-variance-weighted sum of deviations from the mean is consistent with a sum of independent normally distributed differences from the mean.
