“The four most expensive words in investing are: ‘This time it’s different.’” So said Sir John Templeton, the legendary investor and mutual fund pioneer. The phrase contains tremendous wisdom, but only if you truly understand what it means.

Unfortunately, too many investors don’t. Lately, the gem seems to be misapplied and misunderstood. Investors need to understand when specific fundamental factors are different and put them into context.

“This time it’s different” has become a ubiquitous phrase. Google returns more than 6 million results. Professors Carmen M. Reinhart and Kenneth Rogoff even used the phrase as the title for a book they wrote on the history of financial crises: “This Time Is Different: Eight Centuries of Financial Folly.”

So what is the formula for recognizing what “this time it is different” means? (And why is it that it’s never different?)

The answer, I believe, is two parts math, two parts psychology.

The math part begins with the traditional formula for valuation. In its most simple expression, it is price relative to earnings, or the P/E ratio. That is the oversimplified version. There are many other factors that also impact valuation: economic growth, inflation, interest rates, cost of capital, investment options, etc. And there are countless variations of how to measure it. Last year, Merrill Lynch’s quant team looked at 15 metrics that measured equity valuation — but the basic formula is typically a version of price relative to a profit related metric.

As we have seen during various manias, basic valuation measures become disconnected from historical averages. During bull markets, P/E ratios often rise with the stock market. Multiple expansion was responsible for nearly 75 percent of market gains during the 1982-2000 bull market. The Standard & Poor’s 500-stock index began that secular bull market with a P/E of about 8 and ended with a P/E of over 30.

As the bull turned into a bubble toward the end of that 18-year cycle, P/E ratios soared. It was as if valuations no longer mattered. This leads to the second part of the math: Mean reversion occurs. Equity prices eventually revert to their long-term valuation measures. As prices fall, P/E ratios often careen far below that average when panic selling and margin calls force liquidations.

Now let’s look at the “two parts psychology,” which is especially fascinating. When it comes to risking capital in exchange for potential returns, human emotions are two-sided: greed and fear.

Recall the dot-com bubble, when profitless companies soared in price. Initial public offerings were up 500 percent on their first day of trading. Many of these companies were merely a wisp of an idea, and not fully developed firms with real revenue and earnings. It was a new paradigm, and all about “eyeballs” and “clicks” and “registered users” and “first mover advantage.” Profits no longer mattered, despite a century of data that they in fact were the most important valuation measure.

This time was different.

Only, not so much. Within three years, the tech-laden Nasdaq, where most of the high-flying dot-com, tech and telecom companies listed their stock, fell nearly 80 percent from the March 2000 peak. Fourteen years later, the Nasdaq remains 20 percent below its 2000 high of 5,100.

The same can be said of the more recent subprime credit bubble and housing boom. Despite millennia of lending based on the credit worthiness of the borrower, the new metric became the ability of the lender to sell the debt to a third-party securitizer. Traditional measures of median home prices to median income moved almost three standard deviations above normal. Traditional metrics said housing valuations were historically high and unsustainable. They subsequently fell 35 percent nationally.

The investor psychology of the credit bubble was simply to ignore the traditional metrics. Underwrite that mortgage to an unqualified buyer, buy that home despite the huge run-up in prices. History did not matter.

This time was different.

Looking at the booms, we see that phrase has a specific meaning, involving investors caught up in the frenzy of the moment. They allow greed to get the best of them. The collective psychology of the crowd leads to all manner of excuse-making and rationalization as people fall into the throes of a speculative bubble.

I said the formula was two parts psychology; the first part takes place during the booms, the second after the inevitable bust. Greed is replaced by fear. Risk aversion occurs, as the recent past dominates investors’ collective mind-set.

Indeed, since the March 2009 lows, I have been calling this “the most hated rally in Wall Street history.” Markets that are cut in half — as the major indices were — typically bounce back about 70 percent, and as much as several hundred percent. Earnings recoveries of 150 percent are hugely bullish for stocks. Very low rates support higher equity prices.

These things did not matter. Investors pulled money out of the markets and sat on the sidelines.

This time was different.

Human nature is unchanging. During the boom, greed dominates. After the crash, the residual emotion is fear.

Investors need to recognize when the economic environment really is different.

In 1974, the P/E ratio of the S&P 500 was a low 7.33, but inflation was running at 11 percent and the 10-year bond yield was 7.4 percent. Were investors to ignore that different data? By 1981, P/E ratios were about the same, but risk-free yield of the 10-year was more than15 percent.

Some investors dismiss fundamental differences with a wave of their hand, often quoting Templeton in a misinterpretation at the same time. When fundamental factors are very different, it is worth noting. Those investors in the early 1970s who bought stocks because they were cheap were surprised when they got much cheaper. Inflation-adjusted returns in the 1970s hit a loss of almost 75 percent.

It was also different in the 1980s and ’90s: A universe of new technologies emerged — cellular, semiconductors, software, storage, micro-processors, Internet — that really were different. They created a massive amount of new wealth when new industries were created. The investor who refused to buy anything over traditional P/E ratios — despite enormous growth rates and increasing revenue and profits — missed out on an era of generational wealth creation.

Rates are now at unprecedentedly low levels. That’s a fundamental difference from the prior 30 years of inflation and yield on fixed income. There is a lack of competition from fixed-income products for your investment dollar, thereby making equity dividend stocks that much more appealing. This is a significant fundamental difference in the markets and valuation and prices.

Distinguishing between the two is crucial. Identifying when things really are different and when the collective madness of the crowd is in full force is the difference between sitting out a 180 percent rally or participating in it.

You are never different. But sometimes, the data is. The sooner people understand this, the better off their portfolios will be.

Ritholtz is chief investment officer of Ritholtz Wealth Management. He is the author of “Bailout Nation” and runs a finance blog, the Big Picture. Twitter: @Ritholtz.