After 18 months of shutdown agony I was very frustrated. The local Apple Shop could never replicate the problem or find anything wrong with the computer.
In the middle of autumn here in southern Australia the problem became so bad that the computer was shutting down several times a day, including when it was asleep with no programs running or connection to the internet or to the Time Machine backup. It also used to sometimes die when I was shutting the machine down.
The straw that broke the camel's back was when it did that during a restart after a system update and corrupted the operating system so badly that Apple Support suggested I wipe the hard drive and reinstall the operating system from scratch. Even getting the existing information off the computer and onto a portable hard drive became a nightmare because the computer would abruptly shut down while I was doing it.
In desperation I decided to do what others have done and get the local Apple Shop to replace the power supply unit. Before replacing the power supply the local Apple Shop tested the computer again and still couldn't find anything wrong. One month later and I haven't had a shutdown.
If you are having this shutdown problem I would highly recommend that you try replacing the power supply first before spending money on replacing video cards, screens, CPUs etc.
You will probably have to insist that they do that first because they will still argue until the cows come home that it is likely to be one of the other components and not the power supply. Given how often replacing the power supply has solved people's shutdown problems that is not always true.