Can the compass error have been caused by my error and not having performed the proper pre-flight procedures. Note: I did not have to calibrate the compass prior to take-off on this flight.
The problem was that you powered up the aircraft in a magnetically distorted location, and then moved it or turned it:
At takeoff there was a yaw disagreement of nearly 160° between the IMUs and the compass. Looking at the magnetic modulus it appears that the entire first part of the flight was in a distorted magnetic field. The modulus really spiked at 151 s, causing the error.
That didn't matter while it was flying under VPS, but after the NavHealth rose enough for it to switch to a GPS-driven P-mode then uncontrolled flight was inevitable:
Interestingly the FC managed to reconcile the yaw error at around 164 seconds, bringing it back under control - I've not seen that before:
The magnetic environment was so compromised that the usual test – is the aircraft orientation arrow pointing in the right direction at launch – may or may not have worked. It most likely wouldn't have been correct though. To that extent I'd classify this as pilot error, although nowhere does DJI recommend that check.