Can purchase of insurance be justified mathematically? When I ask people to explain why they buy insurance, I often hear vaguely of "spreading the risk", but I am not actually sure what that means nor if insurance does this. How is an insurance company any different than a casino?
In a thought experiment where some large number of people who purchase insurance are compared against an equal number of people who do not, it seems to me when one takes into account the cost of insurance, the people who do not purchase it end up better financially than those who do not. It is argued that insurance is needed to protect against catastrophic events but isn't poverty in old age a catastrophic event also? I realize that these are not strictly mathematical questions but at its base, insurance must be either a good or bad choice based on statistics and probability.
EDIT: More succinctly: Buying insurance is making a bet with a negative expectation. If there is some way to justify this mathematically then are there other bets with negative expectation, like buying lottery tickets or roulette that can be justified and how?
EDIT: People are saying, this is not a mathematical question but the question: Is a person likely to be better off financially if the buy insurance is a pretty mathematical question. If you took 100 people and half bought insurance and the other did not, which group would have more money at the end of some period, is mathematical. I can answer this question about any negative-expectation betting, so why is insurance any different?
 A: I don't think this is strictly speaking a mathematical question - if you doubt this, try to come up with a mathematical definition of "justified" in the sense you want it to be understood. You can mathematically calculate the expected value of buying insurance - which will typically indeed be negative - but mathematics is silent on the question whether one should enter transactions with negative (or positive) expected value.
The question should most naturally be answered from the perspective of economics, which of course uses mathematics.
Most economists would use (expected) utility theory to approach the question whether a specific insurance policy should be purchased. Underlying is the assumption that the increase in "well-being" from wealth is not actually linear, but for most individuals a concave function of wealth, i.e. the more one already has, the less one gains from additional units (this is what economists call declining marginal utility).
Short answer: Expected value might be a bad guide for decisions.
Typically, economists make the assumption that there is some utility function for each individual, mapping wealth to something like "well-being"; supposing this function is known, one could precisely answer the question whether entering such a contract is beneficial.
Suppose $u(\, )$ is said function for the agent in question; he currently posseses total wealth $w$. He is at risk of losing an amount $R$ with probability $p$ (say by a house fire). The agent could (completely) insure against this risk with a policy costing the fixed amount $c$. Then, accepting the policy is beneficial iff
$u(w-c) > p u(w-R) + (1-p) u(w)$
Typically, we observe $c> pR$. (That's how insurers earn money). If $u()$ is linear (or even convex), the agent is better of bearing the risk himself. However, if the curvature of u() around point $w$ is sufficiently concave, purchase of insurance is advised - i.e. it is better to take the sure loss here. (See wikipedia on risk aversion for graphics and more details).
If that's implausible to you, maybe thinking about it reversely can make it more intuitive: would you bet everything you have for a $ 1\%$ chance to win $101 \times$ of what you have? Simple expected value would advise you to, most people would sensibly decline.$^1$
Note that utility theory can of course also be used to think other cases in which accepting negative expected value transactions are advisable. For example, if the pleasure of betting $m$ on red outweighs the costs of losing $\frac 1       {37} m$ in expectation, then the individual might be well advised to play roulette.
Or, one could think about a situation where there's a certain amount of cash one needs desperately. If you have $1500\$$, but would need $3000 \$ $ for a life-saving operation, putting it all up for a biased coinflip might actually be a good course of action, assuming you die just the same whether you have $0\$ $ or $ 1500 \$ $.
Footnote 1: It might be interesting to you that expected utility theory in some sense was first used precisely to tackle the problem of a lottery which has unlimited expected value, and should therefore be "worth" more than any finite amount of money - even though it does not seem all that attractive to most: St. Peterburg paradox
A: Note: This answer is similar to the one of Especially Lime but I try to focus on another aspect. 
The point of insurance just is not to optimize the expected valued but instead it is to decrease variance.   
Suppose every day you leave your home with about 30 dollars in cash for  lunch, coffee and other smaller expenses during the day and assume further you have no credit card and cannot withdraw cash during the day (or borrow some etc.).
What do you prefer: 


*

*losing 10 cents each and every day, or 

*losing all your cash on a random day once a year? 


I'd prefer the former by a lot even though the expected value is worse namely about 36,5 dollars loss per year versus about 30 dollars loss per year.    
Why? Because I could care less about 10 cents a day and even over the span of my entire life the less than 7 dollars loss per year is not really relevant. But on that one random day  each year it could be quite annoying not to have any cash at all during the day.  
To return to the staring sentence in the first case 
I have expected value $-0.1$ dollar per day in the former scenario but about $-0.082$ in the latter (which is better).
However there is zero variance in the first case  while there is significant variance in the second case, both informally as well as in the mathematical sense.   
Summary: Insurance can allow to get a distribution with (much) smaller variance at the expense of a slightly worse expected value. And, this can be desirable. 
A: One reason for certain types of insurance, particularly businesses taking out insurance against certain potential liabilities, but also personal car insurance, is that it is a legal requirement. In that case, of course, it doesn't have to be a bet worth taking in any mathematical sense.
However, other types of insurance can often be justified by a difference in utility functions. Say I risk some event which will cost me £10,000 if it happens, but only has a 1% chance of occurring. A company offers me insurance at £200. This is a good bet for them - they make many of these bets, they are essentially independent, and so it is very unlikely that they will fail to make a profit; even if they do so one year they can make up for it the next. Essentially they have a lot of money (much more than £10,000) and the utility of the various outcomes roughly corresponds essentially to the monetary value, so a positive monetary expectation is what they are looking for.
It could also be a good bet for me, because losing £10,000 is a very bad event, causing me more than 100 times the distress of paying £200. Because £10,000 is a significant proportion of what I have, my utility function is markedly non-linear over amounts of that magnitude (and concave, so losing £10,000 is worse than you might extrapolate from how I feel about losing £200). By "utility" I am talking about a function which translates losses of various amounts of money into how much my well-being would suffer; even though taking out insurance might decrease my expected wealth, it could still increase my expected well-being.
If the bad events are not really that bad - in that you could in extremis afford to pay for them without too much distress - it may well be that insurance isn't worth it to you.
A: The risk of an accident doesn't change at all. What changes is the risk of bankruptcy, which is indeed spread.
If a major accident occurs, you are very likely to be bust (with a probability depending on the distribution of the accident severities), because you are charged the full amount.
But if you took part to risk mutualization (I mean if you contracted an insurance), the probability of company bankruptcy is insignificant and you remain safe as you are only charged the expectation of the damage plus the company fee.
The laws of probabilities do not apply to you alone, as you are dealing with rare events. They do for companies, for which they are daily, and the Central Limit Theorem comes into play.
The larger the spread of the accident severity, the more it is beneficial to take an insurance.
A: Short answer:
The key word is variance reduction.
When you are alone, the distribution of your loss has a huge spread.
When you are many, the expectation remains the same, but the variance is much narrower by the Central Limit Theorem.
This variance reduction has a cost: the insurance fee.
A: Many good answers here about insurance - I hope the OP is convinced. No one has mentioned casino gambling yet.
Your expectation at roulette or the slot machines or any other truly random casino game is indeed negative. The house takes about $5\%$ at the roulette wheel (American), more at the slots. But you might still want to gamble. The adrenaline rush, the dreaming about what you'll do with your winnings, the show, the night out might be worth the expected $5\%$ to you. You can think of it as the purchase price for your pleasure. That could well be less than you'd spend for a good dinner and a movie.
This is essentially just another way to say that to justify behavior you have to think about expectation in personal human terms, not just as an amount of money.
The dollar expectation at blackjack is very slightly positive if the casino isn't taking good precautions against card counting (using multiple decks, inviting counters to please leave) - but you have to work hard at it for a lot of hours to make any money.
Your dollar expectation at poker might be positive since you're playing against other people. If you're enough better than they are than the casino takes from the pot as overhead you can win if you play long enough to even out the randomness of the cards.
State lotteries are the real ripoff in expectation. Your dollar ticket might be  worth about $60$ cents. 
A: Yes, and the justification is called the Kelly Criterion.
This formalizes the idea that a catastrophic event can be worse for someone who doesn't have the resources to absorb it than for someone who can.  It can also be used to tell how much you should bet on a positive-expected-value coin flip.
The coin flip case is easier to think about.  Suppose you where offered a coin flip you can repeat every day for up to 30 years.  You flip a coin, on tails you lose everything you wager.  On heads, you earn twice what you bet, plus a 1% of what you bet.
The expected value of the coin flip when you bet X is then 1.01X
If you bet X at the start and "let it ride", you'd on average end up with (1.01)^365, or a yield of x38.8!  Throw any money you can at this!
On the other hand, if you bet everything you have, the probability you'd have anything at the end of the year is 1 in 2^365, or over 1 in 1 googal (1 followed by 100 zeros).
Clearly you should avoid this bet, and it will almost certainly bankrupt you.
Both of these conclusions are reasonable, but they disagree.  The right solution, in practice, is to bet something in the middle.
The Kelly Criterion tells you how much to bet, as a fraction of your net worth, on such a positive-sum bet.  Basically it tells you to maximize the expected ln of your net worth.
Betting everything makes you average -infinity and something finite; so it tells you not to do this.
In this case, we want to maximize ln(A+X*(1.01)) + ln(A-X)
Kelly says that X/A should be (bp-q)/b, where p is win chance, q lose chance (both 0.5 in this case), and b is the payoff (1.01), or in this case basically 1% of your bankroll (well, actually 0.01/1.01).
Supposing you start with 100$.  Then if you bet 1% of your bankroll and get a 0.5% expected yield, you end up with an average return of 1.00005.  Repeated 365 gives you 1.8% return per year.  Not the 39-fold average return you get by betting everything, but this strategy does not require going bankrupt.

Insurance can be reframed as a Kelly question.  Imagine if the starting case was "fully insured against all loss".
Then, dropping your insurance becomes a positive-expected-value Kelly bet.  Kelly will tell you how much insurance you should have, which can vary from "all of it" to "nothing", given the price of insurance and your ability to recover from the insured-against disaster.
All of this becomes more complex when you add in bankruptcy and the ability to work after losing your assets and the like.
The conclusion ends up being that things like house insurance is worthwhile for "middle class" people in the industrialized world at reasonable prices.  For rich people, the insurance is no longer worthwhile (it becomes better to "self insure"), and for poor bankruptcy ends up being a better choice than paying for insurance.
As it happens, people owning your Mortgage (for houses) and society (traffic accidents) ends up paying when you cannot afford to, so laws and contracts sometimes force you to take out insurance when Kelly says not to.
A: That is why insurance is best for people who are well-off to pay for insurance and hence can secure themselves in any catastrophic event that might occur. It depends on the financial conditions of a person, the probability of any future disastrous events to occur, or to just be insured if there is enough risk of theft or damage.
Poverty in old age is extremely unlikely for a person who is paying for insurance of a thing that cost him/her more than the insurance itself. If the person "can" and is willing to pay for insurance, there should be no reason why they might be financially deprived due to the money they spent, in near future. 
A: I think insurance is justified for the customer in several cases. If you get into accident with 30k usd car four times in your life you are liable for $3 \times 30,000 =90,000$. In general number of accidents per life time $n$ and cost of accident $c_n$, then life time liability is $C_T =\sum^{n}_{i=1} c_i$. Cost of insurance is number of premium payments in lifetime or $P_T$ so you want $P_T \lt C_T$. 
This explains mathematically when insurance is beneficial to you. You can see here, if you aren't paying for the liabilities, the insurance company is. This is supposed to be the case, other wise the company would go bankrupt. So what the insurance can do is spread the liability through out ones life time, ensuring it gets paid or making it more likely. They are your liabillities and you shouldn't expect the insurance company to pay it, or to benefit from it. 
Now sometimes the costs can be more severe than they would have to be, for example there are full coverage and liability only, expensive cars and cheap cars safer drivers and reckless drivers. Someone owning a more expensive vehicle shouldn't be your liability? There are problems with insurance however they aren't just gambling or casinos.
There are many insurance companies and you can even insure yourself. However it requires a lot of money held just for it. 
My opinion is that to agree that insurance today is often broken and unfair. But you should see what it is intended to do. 
I think it would work best if everyone insured their own car, and no fault is given for accidents without lawsuit. Therefore unless sued you aren't responsible for costs associated with other parties. Essentially the consumer pays for the cost to insure their property, so if you drive an 800 dollar junker, you pay proportionally, and likewise if you insure a 70k car, you probably pay more than 300 a month. This makes the insurance schema work. However, anyone can now attempt to sue you and would if it is in their interests. Often courts can not handle this as it is very difficult to prove aspects of a heavily dynamic car accident. Often the current consensus is to just not deal with it, but to make sure everyone is covered by opposite party through insurance. Leading to the problems I mentioned above. Basically we have to over pay to ensure liabilities' are funded for everyone. 
Then considering how car manufacturers may benefit from this, and you pretty much can see why things work the way they do. And today large corporations aren't losing, so it is the consumer who covers the bill, and often the least able to pay it, why I voted for Sanders.
A: You can mathematically justify insurance.  You have to layer in the economic concept of marginal-value to do so.  In short, first consider the basic assertion that for most people, 100M dollars is NOT ten times as much money as 10M dollars.  How can this be so?  Simple, look at how much your life would change if you acquired 10M dollars.  Look at how much your life would change if you acquired 100M dollars.  Is it 10 times the change?  Likely no.
The same can work out for losses.  What is the negative impact of losing 1,000 dollars?  What is the negative impact of losing 1,000,000.  Is it more by over 1,000 fold?  Maybe?
Also, consider the fact that FEAR has a negative value.  Consider that the removal of this fear, fear of loss from an accident, has a positive value.  Is the positive value of the fear removed greater than the cost of that removal?  i.e., the cost of the insurance?
In short, you cannot justify insurance through an expectation value calculation wherein each dollar has an equal value.  You can justify it if you apply the concept of varying marginal values for those dollars.  You can easily justify it when you apply a value to the removed fear.
A: "People are saying, this is not a mathematical question but the question: Is a person likely to be better off financially if the buy insurance is a pretty mathematical question."
This is the wrong question, however.
The point of insurance is to ensure that certain events (dying from treatable diseases; being financially ruined by a flood or car accident) do not happen.
So, given that without insurance, a percentage of people will get such events, you can consider two populations:
1) The population of people who did not get insurance, which includes some affected by these condition.
2) The population of people who did get insurance, which includes some who would have been affected by, but are instead protected from, this condition.
So, to do this "math" for healthcare alone, you have to assign a value to:


*

*dollars, which will be non-linear. 100k dollars per year will have more than 100k times the value you place on a dollar per year.

*chances of saving your life, which will be non-infinite, but the value will likely also have a non-linear relationship to risk: avoiding certain death will be worth far more than 100k times more than avoiding a 1-in-100k chance of death.

*chances of losing your job to ill health.

*saving worry about the above effects happening.

*the savings on meds and other purchaseables (just for the cost of meds alone, my family covers the cost of healthcare, since healthcare companies can negotiate big discounts)

*the savings on medical procedures, checkups, and so forth.

*and so forth.


All of these will vary from person to person, and each item has a very complex relationship to whichever measure of "value" you choose.
So: yes, it's a mathematical question, but how you define the relationships between "what it's worth to you" and "what it costs you in dollars" is intensely personal and individual, and will change over time.
Alternatively, think of it like buying a hunting or driving license. Buying a license gets you immunity from a fine for not having it. But if you live somewhere where you're unlikely to get caught, and you drive well, and you don't mind a few arrests, and paying for the license would be ruinous to you, then maybe you have a case to risk not getting the license.
For most people, getting the license just makes more sense - it prevents those completely avoidable periods in jail, or having the car impounded, etc.
So, we can't tell you what math you should apply to getting insurance. Financially, if all you count is dollars, you will on average end up with fewer dollars if you buy the insurance (or license). But that dollar value does not account for the non-linearity of worth of a dollar, and so does not give the correct value to the cases where the dollars are needed the most, and the value of the knock-on effects (loss of job, car, home, life) of not having those dollars when they were needed.
With gambling, you buy hope. With insurance, you buy confidence.
