The extent to which self-adopted or intervention-related changes in behaviors affect the course of epidemics remains a key issue for outbreak control. This study attempted to quantify the effect of such changes on the risk of infection in different settings, i.e., the community and hospitals. The 2002-2003 severe acute respiratory syndrome (SARS) outbreak in Hong Kong, where 27% of cases were healthcare workers, was used as an example. A stochastic compartmental SEIR (susceptible-exposed-infectious-removed) model was used: the population was split into healthcare workers, hospitalized people and general population. Super spreading events (SSEs) were taken into account in the model. The temporal evolutions of the daily effective contact rates in the community and hospitals were modeled with smooth functions. Data augmentation techniques and Markov chain Monte Carlo (MCMC) methods were applied to estimate SARS epidemiological parameters. In particular, estimates of daily reproduction numbers were provided for each subpopulation. The average duration of the SARS infectious period was estimated to be 9.3 days (+/-0.3 days). The model was able to disentangle the impact of the two SSEs from background transmission rates. The effective contact rates, which were estimated on a daily basis, decreased with time, reaching zero inside hospitals. This observation suggests that public health measures and possible changes in individual behaviors effectively reduced transmission, especially in hospitals. The temporal patterns of reproduction numbers were similar for healthcare workers and the general population, indicating that on average, an infectious healthcare worker did not infect more people than any other infectious person. We provide a general method to estimate time dependence of parameters in structured epidemic models, which enables investigation of the impact of control measures and behavioral changes in different settings.