I don't think a formula can or does exist. Mathematically (I am not a mathematician), I think the problem can be solved by modeling the network (or a portion of it) and adding or removing sidings on single-track segments and stochastically modelling the effects on traffic and costs for various situations. The situations should be normal (short train has to wait for long train because of bad timing), typical problems (cascading effects of a late train or minor equipment problem like an engine that won't start, but there are multiple engines or heat delays or missed slots), critical (derailment that doesn't rip up the tracks, disabled train on a single-track segment, grade-crossing collisions) or catastrophic (major derailment like East Palestine, bridge or tunnel collapse or fire, etc.) Then the model has to evaluate various improvements, such as longer or additional sidings, double tracking, adding signaling for dark territory, improving track or signaling to allow faster trains, etc.)
The costs of delays needs to be evaluated and include repayments to customers for missed deliveries or missed connections (including hotels), medical, damage and cleanup costs for collisions and derailments, opportunity costs for when a route is out of service, and HUGE FINES for delaying passenger trains (looking at you, FRA and whatever government regulatory agencies are involved. There are also externalized costs, such as the costs paid by drivers and truckers waiting at grade crossings for 2-mile-long, 20 MPH freight trains to clear the crossing (time, fuel, etc.) The railroads should be accountable for externalized costs.
The costs of improvements are highly variable, depending on whether single-track line was formerly double-tracked and the ROW hasn't been encroached on or sold off, whether the bridges and embankments are still adequate or need upgrading, etc. Definitely NOT a single cost-per-mile, some improvements cost many times as much as similar improvements at other locations.
The benefits of improvements are much more than risk reduction. Faster trains means crews get paid less or can go greater distances before timing out. Existing infrastructure can be used more efficiently reducing fuel costs. Railroads should be charged for externalized costs, but also be rewarded for externalize benefits like reduced pollution (vs trucks or planes), and lowering their carbon footprint. If a carbon-tax or carbon-credits system were introduced (which I think is inevitable over the next decade or two), these benefits would accrue naturally to any business that improved its resource usage efficiency.
I'm sure large railroads have used such models for decades, but they've probably misused them to over-simplify and increase quarterly profitability over long-term sustainability. (Guy in a top hat and monocle: "If we tear up the second tracks on all our lines and don't do any maintenance, our profits will soar until everything collapses, and then well demand a bailout. What's not to like? How much will we save in expenses until bad stuff happens? Do it!")
Done ranting for a while...