Leaving an unstable country in some regions is an invite to further international problems. This was the case with Afghanistan in the 1990s, which resulted in Al-Qaeda being hosted there. This was the case with Somalia, which not only hosted elements of Al-Qaeda, but also conducted rampant piracy. This was the case with Iraq/Syria, which gave the Islamic State a huge opening and resulted in them seizing the second largest city in Iraq. It seems a bad idea to ignore these areas, even though there is a cost to not ignoring them.
The cost of not ignoring them is one must maintain a presence of something like 2,000 to 20,000 or more support troops, Air Force personnel, trainers, advisors, special operations forces, etc. And they must be maintained for a while. It will certainly result in the loss of a few American lives, perhaps even dozens. It will certainly cost hundreds of millions to pay for deployment, security operations, develop the local forces, and to re-build and re-vitalize these areas. In fact, the bill usually ends up costing billions. Furthermore, these operations go on for a decade or two or more. The annual cost times 20 years gets considerable. We have never done any studies of “security operations” or “advisory missions.” The focus of our work was on insurgencies, but we have no doubt that these things tend to drag on a while before completion.
The cost of ignoring these countries may be nothing. If there is no international terror threat and no direct threat to our interests, then there may not be a major cost to withdrawing. On the other hand, the cost of ignoring Somalia was a pirate campaign that started around 2005 and where they attacked at least 232 ships. They captured over 3,500 seafarers. At least 62 of them died. The cost of ignoring Afghanistan in the 1990s? Well, was it 9-11? Would 9-11 have occurred anyway if Al-Qaeda was not free to reside, organize, recruit and train in Afghanistan? I don’t know for sure…..but I think it was certainly an enabling factor.
I have never seen a study that analyzes/estimates the cost of these interventions (although some such studies may exist).  Conversely, I have never seen a study that analyzes/estimates the cost of not doing these interventions (and I kind of doubt that such a study exists).
Hard to do analyze the cost of the trade-off if we really don’t know the cost.