A solution to the ecological inference problem