What is the origin of the phrase dead ringer?

People would be buried with a rope leading from inside the coffin to a bell above the ground. This enabled anyone who was buried alive to ring the bell and to draw attention to the mistake. Since people would not expect to see their 'dead' loved ones again, a person resembling the deceased is a 'dead ringer'. This is also reputed to be the origin of the expression 'graveyard shift' because people from the village used to take it in turns to listen for the bell.

According to The Phrase Finder:

A ringer is a horse substituted for another of similar appearance in order to defraud the bookies. The word originated in the US horse-racing fraternity at the end of the 19th century. The word is defined for us in a copy of the Manitoba Free Press from October 1882: "A horse taken through the country and trotted under a false name and pedigree if called a 'ringer.'"

This source also discounts the graveyard as the source of the phrase "saved by the bell"
I'm only nine so it means buried alive.