Testing general relativity using Bayesian model selection: Applications to observations of gravitational waves from compact binary systems