Railway safety is an important issue of transportation system. In this paper, a network model is proposed for the risk analysis of railway system combined with the Fast Newman community detection algorithm. In the network model, nodes represent accident causation factors and links are generated if the two factors occur in one accident. Employing Fast Newman algorithm, the network is divided into communities. By defining occurrence possibility and consequence severity, the risk of accident is quantified. The rail equipment accident data from 2010 to 2014 is chosen for analyzing. The analyzing results show that the risk caused by the factor of switch improperly lined is the highest in the system and human factors play an important role in railway accident causation. The constructed model can quantify the risk, and hence, it gives methodological support for railway accident prevention.