This conversation is confusing. How can you get heading information without a compass? If the heading is wrong, I have usually found that calibrating the compass fixes it. Having said that, COG and heading on my boat are never fully in sync, even when just motoring. I think drift and leeway are conflating the reading.
I cannot match the high-techg replies you have had but i had a similar problem and found that one of my crew had been charging their phone from the socket on top of the cupboard where the electronic compass was located.
Andrew
Here is something understandable from years ago. My brother got lost in the fog following his compass and illegally tied to a nav bouy until he could ask a passing fellow fisherman what direction to head. When he learned where north really was, he suddenly realized that he had put his knife down next to the compass! After that he was able to make his way home in the fog.