I am following professor David Tong's lecture notes on Statistical Mechanics and on page 9 of this file http://www.damtp.cam.ac.uk/user/tong/statphys/one.pdf he states that the expected value of an operator $\hat{\mathcal{O}}$ is $$ \langle \hat{\mathcal{O}} \rangle = \sum_{n} p(n) \langle n | \hat{\mathcal{O}} | n \rangle, $$ where $|n \rangle$ is the basis for the states which have the specified energy $E$ (in the microcanonical ensemble) and $p(n)$ is the probability of finding the system in such a state.
Well, given an arbitrary state $| \psi \rangle$, then $$ | \psi \rangle = \sum_{n} c_{n} |n \rangle, $$ where $p(n) = c_{n}^{*} c_{n} = |c_{n}|^{2}$. We also know from Quantum Mechanics that the expected value of an operator $\hat{\mathcal{O}}$ at a state $| \psi \rangle$ is given by $\langle \psi | \hat{\mathcal{O}} | \psi \rangle $. Using the expansion of $| \psi \rangle$ in the basis $|n \rangle$ we have $$ \langle \psi | \hat{\mathcal{O}} | \psi \rangle = \sum_{m,n} c_{m}^{*} c_{n} \langle m | \hat{\mathcal{O}} | n \rangle. $$ I used two different indices because there are two sums (one for the bra and another one for the ket).
Could someone explain the disagreement between the two equations?