Two analytical approaches were used to investigate the relationship between somatic cell concentrations in monthly quarter milk samples and subsequent, naturally occurring clinical mastitis in three dairy herds. Firstly, cows with clinical mastitis were selected and a conventional matched analysis was used to compare affected and unaffected quarters of the same cow. The second analysis included all cows, and in order to overcome potential bias associated with the correlation structure, a hierarchical Bayesian generalised linear mixed model was specified. A Markov chain Monte Carlo (MCMC) approach, that is Gibbs sampling, was used to estimate parameters. The results of both the matched analysis and the hierarchical modelling suggested that quarters with a somatic cell count (SCC) in the range 41,000–100,000 cells/ml had a lower risk of clinical mastitis during the next month than quarters <41,000 cell/ml. Quarters with an SCC >200,000 cells/ml were at the greatest risk of clinical mastitis in the next month. There was a reduced risk of clinical mastitis between 1 and 2 months later in quarters with an SCC of 81,000–150,000 cells/ml compared with quarters below this level. The hierarchical modelling analysis identified a further reduced risk of clinical mastitis between 2 and 3 months later in quarters with an SCC 61,000–150,000 cells/ml, compared to other quarters. We conclude that low concentrations of somatic cells in milk are associated with increased risk of clinical mastitis, and that high concentrations are indicative of pre-existing immunological mobilisation against infection. The variation in risk between quarters of affected cows suggests that local quarter immunological events, rather than solely whole cow factors, have an important influence on the risk of clinical mastitis. MCMC proved a useful tool for estimating parameters in a hierarchical Bernoulli model. Model construction and an approach to assessing goodness of model fit are described.