It turns out that all animals and humans have what researchers call a built-in confirmation bias. Animals and humans are wired to believe that when two things happen closely together in time it's not an accident; instead the first events caused the second thing to happen.
On farms, pigs get fed one at a time inside small electronically controlled feeding pens. Pigs can get into really nasty fights over food, so farmers use the pens to keep the peace. All the pigs wear electronic tags on their collars that work something like an electronic pass at a tollbooth. When a pig walks over to the feed pen a scanner reads the tag and opens the gate, then shuts the gate behind the pig so none of the others pigs can get in. The sides of the pen are solid, so the other pigs can't reach their snouts inside and bite the tail or rear end of the pig who's eating.
Once a pig is inside the pen she has to put her head up close to the feeding trough where another electronic scanner reads the ID, then measures out the exact amount of food that pig is supposed to eat.
Some of the pigs figure out that it's the collar that lets them into the feeding pen, and if they see a loose collar lying on the ground they'll pick it up and carry it over to the pen and use it to get inside. In that case confirmation bias has led to the correct conclusion about the nature of reality.
But other pigs develop superstitions, also based in confirmation bias, about the feeding trough inside the pen. I saw several who would walk over to the feeder and go inside when the door opened, then approach the feed trough and start doing some purposeful behavior like repeatedly stomping their feet on the ground. They kept doing this until their heads happened to move close enough to the pen scanner to read their tags and deliver their food. Obviously they had had food delivered a couple of times when they happened to be stomping their feet, and they'd concluded it was the foot stomping that got them food.
People and animals develop superstitions the exact same way. Our brains are wired to see connections and correlations, not coincidences and happenstance. Moreover, our brains are wired to believe that a correlation is also a cause. The same part of the brain that lets us learn what we need to know and find the things we need to stay alive is also the part of the brain that produces delusional thinking and conspiracy theories.
Small Extract from the bestseller "Animals in Translation" by Temple Grandin and Catherine Johnson published by Bloomsbury, 2005