Density increases the number of potential criminals you pass but also increases the number of alternative victims they could target.
If you're a uniquely attractive/visibly wealthy personal walking home from a night out then the risk of passing more criminals dominates the advantage of alterative targets. After all, there's nothing really competing with you.
However, if you look like normal person but happen to have a million dollar watch in your pocket then you're conceivably safer in a city. Because there'd be so many alternative victims who may be more attractive targets than you. Compared to the countryside robber who only gets a single target per night.
Obviously this isn't every crime! People do have unlikely crimes happen to them all the time! Just that they're statistical anomalies and the population level statistics will mislead you about how high your risk is.
Depends on behavior. If I stay in my room all day, I don't contribute to your divisor. If Jack Dorsey doesn't walk around alone past midnight, he's not absorbing the same risk quotient either.
Jack Dorsey is a weird motherfucker and a real outlier for this example. He used to walk to the Twitter office every day and generally looks and dresses like someone well outside his economic strata. I would not be surprised to find “midnight solo perambulations through the tenderloin” among his hobbies.