with a risk model based on standard deviation how can you account mathematically for the added risk of buying with margin. I can't for the life of me figure out how to include margin in my calculation of risk. I know its important but I just can't find formula or any info on how this works.

What is the question? the "added risk" is mainly the higher volatility due to leverage. Just factor in the - leverage factor.

Understood but how do you include the leverage into the standard deviation to give the increased risk calculation.

What equation/s using standard deviation are you attempting to work with? Perhaps the following is coming at this from the wrong direction relative to what you're trying to achieve, but perhaps think of margin as the equity level below which ruin occurs?