Ice on a roof can happen naturally with quick changes in the weather but more often than not the problem starts in the attic. When ice forms on the shingles near the eaves it is generally due to heat buildup in the attic that melts the snow on the roof causing ice damming and leaks.  A properly designed home will provide an air space at the eaves called soffit vents. These vents allow cool outside air to enter the attic at the eaves and literally mix and push the warm air up and out the roof and gable vents. When all the vents are sized and designed correctly that attic should stay cold throughout the winter and cool most of the summer. Lack of insulation or too much insulation in places also contributes to ice damming. Vapor barrier is also a critical component. 

This old house magazine has a great pictorial view of this process ad some helpful tips as well. Click here another great website I came across is here.