Every study made suggests spray as the best alternative.
For the bear, almost certainly!
Looking at this somewhat realistically, and trying to avoid being too macho, the simple truth is, EVERYTHING FAILS.
Personal firearms, in order to be effective must be used as precision implements. Doesn't matter if you're shooting bunnies or biggest bears, if YOU don't put the bullet in the right spot, it won't work the way you want it to work. (and of course the bullet has to be able to get to the right spot, as well)
This takes either sufficient skill or sufficient luck, or both together.
Bear spray is more of an area denial weapon. Non lethal, and spray, so pinpoint accuracy is not required. I'd venture to say the AVERAGE person would be more likely to be capable of the needed accuracy (under extreme stress) with a spray than a gun.
That being said, statistically I'd expect more people capable of effectively delivering bear spray than effective shooting in the typical "charging grizzly" scenario so often discussed.
Studies, first off, look at what worked, and HOW OFTEN. And while the data might be (and usually is) accurate, and the math will be accurate the conclusions drawn from the math might not accurately represent all real world situations.
As an example of a possible conclusion, lets use simple numbers in our "study". lets say we have 10 cases of bear attack, 6 used bear spray, 4 used guns. Lets say both the spray and the guns FAILED to stop the attack half the time. Spray wins by 3 to 2. That's math.
Someone might conclude spray is better because 3 is more than 2. That's a conclusion, its based on math, but its not math.
The same exact process could (and often is) used when discussing which caliber (or load, bullet weight, shape construction, pick a variable, etc) is "best".
Someone will come up with a study, using real world situations, then boil those down to a number, usually using one, or perhaps two factors, and ignoring all the other factors that make each and every incident unique. They will then work some math on those numbers, and present a conclusion, proclaiming whatever has the higher numbers to be "the best".
What ever they say is the best, might be, but it isn't the best just because they say it is, and their numbers often don't mean squat in the real world.
If you ever face a bear, or every time you face a bear, none of the factors in your situation will be identical to what is in the studies, beyond the fact that a human and a bear are involved.
Studies, statistics and their conclusions are useful as general background information. I think blind adherence to anyone's conclusions about what you will face based on their studies is misplaced faith.
There is only one advantage I can see to carrying spray OR a gun, and that is if you only have one, you won't waste any time being confused over which one to use.
Other than that, I think carrying BOTH is the better choice. Spray for when you want to discourage a curious bear, a suitable firearm (and the skill to use it) for when you need to stop an angry bear.
Guns are not magic talismans. Bears are not impressed with what your gun says on it or the size of the hole in the barrel.
I've been shooting .44mag power level pistols, and up, recreationally for going on 40 years. I know what I can do with them, and more importantly, I know what I can't do with them. I've also seen .30-30 bullets bounce off a black bear's skull.
Part of the basic skill you need to defend your self with a gun in a bear attack is knowing enough bear anatomy to know where you should aim. They aren't quite the same as people.
I'll freely admit to being an armchair general on the subject, as I've never been attacked by a bear. I have hunted black bear and that is a much different thing than stopping an attack.
and I'm on a rant, sorry...
of the handguns I have, right now, for stopping a bear attack, I'd pick my LAR GRIZZLY .45Win Mag. For me, it just locks into my hand solidly, its a 1911A1 pattern gun with a good trigger, Millett sights (easily seen) and the firepower of a .44 Magnum revolver, in a package I can shoot slightly faster and as accurately as I can a .44 mag revolver. But that's just me. For you, probably not a practical choice.
2nd choice would be my Ruger Blackhawk .45 Colt and my handloads. Not because its the fastest or most powerful thing possible but because I've been shooting it since 83 and I'm very familiar with the gun and the load at ranges from 0-200yds.
the best defense is, of course, the Miyagi defense.
"no be there!"
failing that, the best is "no be surprised!" and the best tool is your feet. RETREAT, don't run. Spray is a fall back plan, and a gun is a GOTH plan (when all other plans GO To Hell).