There's no way to know this for sure. I've heard sometimes spirits emit an electromagnetic field, but I don't know if that has to do with their death or not. It probably revolves around the fact that they are still energy. What I believe is that when we die, we will be aware of all the mysteries that we had to wonder on Earth... or at least some of the mysteries. Perhaps our soul will still search the universe for answers, perhaps infinately. But for now, no one can be 100% sure on how one becomes a ghost. Of course, there are theories... I'm not familiar with many of them. And who knows, maybe one does not have a choice on wether to pass on or hang around. Maybe it depends on the life you live on Earth. There are many mysteries. This is what I believe, anyway.
Good luck on your quest for answers.