I've done the math on this many times, and it still puzzles me how anybody would choose to buy a house in the Bay Area today versus renting an equivalent one. When mortgages are over 2x rent, the calculation skews tremendously in favor of renting and investing the difference in an index fund. This considers all possible factors and even chooses favorable conditions for homeowners (high appreciation, low stock market returns, high rent increases y/y). The permanent costs of owning a home (property tax, insurance, HOA, maintenance) are typically around 40% of rent, but can be even higher for certain types of property.
My conclusion every time I've done this exercise is that you should only buy a house in the Bay if you have way more money than you know what to do with. The difference in opportunity cost is absolutely massive, on the order of half a million today-dollars or more for a 3-bedroom SFH. That's a huge price to pay for the "privileges" of homeownership.