This is similar to the Q how much does an HOA fee cost? What is the buying power that it costs.
My answer, in Excel format, would be:
mortgage rate is r
PMI is i
Principle is P
Number of months is N
The mortgage payment for the loan only is pmt(r/12,N*12,-P) = K
You are actually paying K + i
So, to determine the effective rate, you want to solve for R such that
K + i = pmt(R/12,N*12, -P)
It's a useful exercise b/c it answers the question "by not putting down 20% to avoid PMI, I am effectively paying R rather than r".
The twist that makes it a little harder is that PMI will disappear as soon as you reach 20%+ equity (not automatically, you need to contact the bank and then cancel). If you are interested, I can provide some formula for that. No PMI would be reached within 5-7 years. In this case you have:
Principle = sum over time with PMI (discount K+i at rate R) + sum over time after PMI is not required(discount K at rate r)