This problem has a few levels, and so a couple of revisions to the laws are in order.
What we want to look at, from the defender's point of view, is the likelihood of conceding a goal under two circumstances: foul and concede a free kick, or don't foul and let the attacker continue with whatever advantage he has gained in the run of play. The likelihood of conceding a goal under both scenarios varies greatly and systematically with the exact spot on the field we're talking about. That is, there's an average probability of conceding a goal from a set piece from any position on the field, and there's a (harder to estimate, and measure) probability of conceding a goal after an attacking player has beaten a defender, again for each spot on the field. In a perfect world, the probability function for set pieces would be at all points higher than the other function, and the functions would be identical in shape. In truth, this is far from true.
A simple example: today, Altidore was held back cynically right outside the Slovenian penalty area, on what would have been a clear chance at goal. A curious fact about free kicks outside the penalty area is that they are actually much more difficult to convert to goals when the ball is placed closer than about 21 yards from goal than if it is in the 21-25 yard range. For a free kick so close to the goal, it's much harder to get the ball up and over the defending "wall," but down under the crossbar. In this case, the Slovenian defender had a positive incentive to foul. [This particular instance relates also back to my earlier post about penalties.] The important point is this: obviously, the closer an attacking player is to goal in the run of play, the more likely he is to score, on average, but defenders have increasing incentive to foul as the player approaches their penalty area because the chance of converting on the resulting free kick actually declines.
So what to do? Again, a simple, elegant solution: However far a foul occurs from the center of the goal, the attacking team should be allowed to take the free kick from anywhere of equal or greater distance to goal. This would allow attacking teams to play to their strengths, and would eliminate any increased incentive to foul as players get closer to the goal, or if they wide instead of in the center.
This questions is also ripe for empirical study. What are the relevant probabilities, and how acute is the problem I've highlighted? I'd love to see some data here. At least for set pieces, this should be relatively easy to collect.
The other level of the problem concerns fouling far from goal when there's no chance of a goal from the resulting set piece. But it's late, so I'll write about that next time.