Prediction of non-suicidal self-injury (NSSI) among rural Chinese junior high school students: a machine learning approach Authors: Zhongliang Jiang, Yonghua Cui, Hui Xu, Cody Abbey, Wenjian Xu, Weitong Guo, Dongdong Zhang, Jintong Liu, Jingwen Jin, Ying Li Published: 2024 ABSTRACT AimsNon-suicidal self-injury (NSSI) is a serious issue that is increasingly prevalent among children and adolescents, especially in rural areas. Developing a suitable predictive model for NSSI is crucial for early identification and intervention.MethodsThis study included 2090 Chinese rural children and adolescents. Participants’ sociodemographic information, symptoms of anxiety as well as depression, personality traits, family environment and NSSI behaviors were collected through a questionnaire survey. Gender, age, grade, and all survey results except sociodemographic information were used as relevant factors for prediction. Support vector machines, decision tree and random forest models were trained and validated by the train set and valid set, respectively. The metrics of each model were tested and compared to select the most suitable one. Furthermore, the mean decrease Gini index was calculated to measure the importance of relevant factors.ResultsThe prevalence of NSSI was 38.3%. Out of the 6 models assessed, the random forest model demonstrated the highest suitability in predicting the prevalence of NSSI. It achieved sensitivity, specificity, AUC, accuracy, precision, and F1 scores of 0.65, 0.72, 0.76, 0.70, 0.57, and 0.61, respectively. Anxiety and depression were the top two contributing factors in the prediction model. Neuroticism and conflict were the factors that contributed the most to personality traits and family environment, respectively, in terms of prediction. In addition, demographic factors contributed little to the prediction in this study.ConclusionThis study focused on Chinese children and adolescents in rural areas and demonstrated the potential of using machine learning approaches in predicting NSSI. Our research complements the application of machine learning methods to psychiatric and psychological problems.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12991-024-00534-w. Introduction Non-suicidal self-injury (NSSI) refers to the deliberate and repetitive act of harming one’s body without the intention of committing suicide [1]. While the prevalence of NSSI varies across different countries [2, 3], it is a significant global public health issue [4]. It is particularly common for individuals to start engaging in NSSI behaviors during childhood and adolescence [5]. Previous studies have found that the average lifetime prevalence of NSSI in global school samples is 17.2% [6], whereas this rate significantly decreases in adults and older individuals, with rates of 13.4% and 5.5%, respectively [7]. The prevalence of NSSI varies between countries, ranging from 13.0 to 46.5% [8, 9]. There are several theories that explain the factors contributing to the occurrence of NSSI. According to the developmental pathology model [10], individuals may face challenging situations during their development, such as identity and role confusion [11] and changes in individual hormone levels [12], which can hinder the development of a strong sense of self. As a result, they may resort to self-injury as a way to regulate or cope with problems. The “four-function model” proposed by Nock et al. [13] suggests that NSSI serves four main functions: positive and negative reinforcement from both oneself and society. Individuals may engage in NSSI to release emotions, gain attention, experience pain, or escape from reality. Due to various external factors and motivations behind self-injury, some adolescents may not actively seek help when they engage in NSSI [12]. They may even hide or conceal their self-injurious behavior, making it challenging for parents or teachers to identify emotional or behavioral issues. NSSI can lead to a range of negative consequences, including, in severe cases, an increased risk of suicidal behavior [14]. In the interpersonal theory of suicide [15], it is mentioned that suicide behavior consists of suicidal desire and capability for suicide. When individuals experience thwarted belongingness and perceived burdensomeness simultaneously, suicidal desire may arise. Increasing physical pain tolerance or experiencing repeated physical pain can gradually develop the capability for suicide. The coexistence of suicidal desire and capability for suicide may lead to the occurrence of suicidal behavior. NSSI have similar pathways with suicide, such as feelings of thwarted belongingness, perceived burdensomeness, or experiencing physical pain repeatedly. This might explain why NSSI can lead to suicide. These factors highlight the importance of timely detection and sensitive prediction of NSSI as crucial factors for effective intervention. Previous studies have identified two main categories of risk factors for NSSI: individual factors and environmental factors [16]. Individual factors encompass biological factors, personality traits, and emotional symptoms. Currently identified biological factors possibly associated with NSSI mainly include dysregulation of the hypothalamic-pituitary adrenocortical (HPA) axis [17], functional changes in the prefrontal cortex of the brain [18], and decreased levels of β-endorphin and met-enkephalin [19]. Among personality traits, neuroticism is currently the most widely recognized, characterized by emotional instability, and has been identified as an independent predictor of NSSI occurrence [20]. In a meta-analysis conducted by Wang et al., anxiety and depression were found to be the most common emotional symptoms that may affect the occurrence of NSSI. In addition to these, the impact of personality disorders and adjustment disorders on NSSI has also been reported [21]. When it comes to children and adolescents, environmental factors such as the school and family environment also play a role in influencing NSSI. The family environment, in particular, serves as a crucial external context for individual growth and development, with a significant impact on the formation of an individual’s judgment and behavioral patterns [22]. A healthy family environment acts as a protective factor against NSSI occurrence. Research by Brasfield [23] indicated that an unhealthy family environment inhibits an individual’s ability to regulate emotions, increasing the likelihood of NSSI when faced with difficulties or frustrations. On the other hand, a healthy family environment serves as a protective factor against NSSI [24]. In addition, interpersonal relationship problems, financial pressures, educational stress, as well as experiences of discrimination and rejection from the outside world, are all environmental factors that may influence the occurrence of NSSI [25]. Traditional data processing methods often face challenges in handling high-dimensional data and exploring complex nonlinear relationships in data [26], such as the Cox proportional hazards model [27], while machine learning methods can address complex data structures by combining numerous variables with high-dimensional data [28]. Machine learning models are extensively used in various fields such as medicine, chemistry, and industry due to their intelligence, scalability, and ability to handle large datasets, yielding reliable results [29]. Machine learning consists of unsupervised machine learning and supervised machine learning [30]. Unsupervised machine learning refers to finding relationships within data structures in the absence of measured outcomes or labels; thus, it is mainly used for descriptive tasks and identifying data structures [31]. Supervised machine learning identifies patterns in multidimensional data based on labeled data and is mainly used for prediction, identification, classification, and so on [32]. In the medical field, machine learning models have shown unique advantages in classifying disease levels and predicting disease prognosis [33–35]. Within the realm of psychiatric disorders, machine learning models have also been applied. For instance, Mansson et al. [36] utilized support vector machines (SVM) models to predict the outcomes of cognitive behavioral therapy for patients with social anxiety disorder (SAD), while Schmitgen et al. [37] employed random forest models to predict treatment outcomes for patients with borderline personality disorder. In addition, the random forest model has also shown good performance in predicting suicidal behavior among adolescents and college students [38, 39]. The advantage of machine learning models lies in their ability to more accurately explore both linear and nonlinear relationships in medical issues. Therefore, in this study, we employed several machine learning models that have previously been applied in psychiatry and neurology, including SVM [40], Decision Tree [41], and Random Forest [42]. While previous studies have explored the factors influencing NSSI, it is crucial to examine these factors in contexts that have not been extensively studied, such as rural areas in mainland China. The reason why previous studies could not be well generalized in rural China mainly lies in the national conditions of it. In China, the college entrance exam is perceived by many low-income families as an opportunity to change their fate due to its perceived fairness. This puts immense pressure on students to perform well. Consequently, parents often place significant emphasis on their children’s academic performance, potentially creating a high-pressure family environment that contributes to emotional problems [43]. Another important factor to consider is the prevalent issue of left-behind children in China [44]. The high prevalence of left-behind children may result in a lack of social support, which can also contribute to the occurrence of NSSI [45]. Hence, it is meaningful to examine the relationship between NSSI and factors such as the family environment within the context of Chinese cultural characteristics. Past studies have revealed that the higher prevalence of NSSI in Chinese rural samples may be attributed to cultural and sociodemographic factors in China [46]. With economic development, China’s urban areas have been rapidly growing, attracting a large number of rural workers to migrate to cities for work [47]. This has resulted in a further decrease in the rural labor force. The reduction in rural labor force has widened the economic and resource disparities between rural and urban areas. For example, in terms of education, although China has implemented nine-year compulsory education in rural areas, the disparity between urban and rural areas is not only in terms of enrollment. The gap in teaching quality between urban and rural areas remains a challenge [48]. This disparity in educational and economic resources may contribute to a poorer family environment, increasing the prevalence of emotional problems among rural youth who may resort to NSSI as a coping mechanism [49]. Additionally, it has been noted that the physical health of rural children in China is generally poorer than that of their urban counterparts, which could also influence the occurrence of NSSI [50]. Due to the high prevalence of NSSI and its significant impact on the physical and mental health of children and adolescents, establishing an appropriate prediction model for NSSI is crucial. This study collected multiple factors influencing NSSI in children and adolescents, including general demographic data, anxiety, depression, personality traits, and family environment. Several machine learning models, including support vector machines (SVM), decision tree, and random forest models, were then constructed to predict NSSI. The predictive performance of different models was compared to select the most suitable prediction model for this study. Finally, the importance of factors related to NSSI prediction was output. Methods Participants and procedure This cross-sectional study was conducted in December 2021 using a convenience sampling method in three county-level junior high schools in Shandong Province, China. In this study, a questionnaire was administered to all students in the selected schools. Prior to the survey, written informed consent was obtained from the respondents and their guardians. The staff involved in the survey received uniform training, which included instructions on survey procedures and privacy protection. The questionnaires were distributed and completed in class, with each class teacher responsible for maintaining order and ensuring that students answered the questions in order. To ensure the accuracy of the data, the completed questionnaires were collected immediately after completion. Following the survey, professional staff reviewed the questionnaires to identify and eliminate any omissions or unreasonable responses. We distributed a total of 2900 questionnaires. After excluding participants who withdrew from the study, blank questionnaires, and invalid responses, we received a total of 2376 valid questionnaires, with a response rate of 81.9%. In the questionnaire, we included a question (Please select whether you come from a rural or urban family) to differentiate between rural and urban students. Out of the 2376 questionnaires, there were 2090 respondents from rural areas. The study’s framework is illustrated in Fig. 1, and further demographic details of the participants can be found in Table 1. Fig. 1Flowchart showing the research process Flowchart showing the research process Table 1Demographic characteristicsN (%)Mean age (SD)NSSI prevalence (n)Total rural sample2090 (100)13.68 (0.991)38.3% (800) Male1007 (48.2)13.72 (0.986)34.8% (350) Female1083 (51.8)13.64 (0.995)41.6% (450) Junior high grade 1676 (32.3)12.73 (0.634)43.5% (294) Junior high grade 2766 (36.7)13.69 (0.597)35.9% (275) Junior high grade 3648 (31.0)14.65 (0.666)35.6% (231)Legend The content of this table is a description of the basic information about the participant Table 1Demographic characteristicsN (%)Mean age (SD)NSSI prevalence (n)Total rural sample2090 (100)13.68 (0.991)38.3% (800) Male1007 (48.2)13.72 (0.986)34.8% (350) Female1083 (51.8)13.64 (0.995)41.6% (450) Junior high grade 1676 (32.3)12.73 (0.634)43.5% (294) Junior high grade 2766 (36.7)13.69 (0.597)35.9% (275) Junior high grade 3648 (31.0)14.65 (0.666)35.6% (231)Legend The content of this table is a description of the basic information about the participant Demographic characteristics Legend The content of this table is a description of the basic information about the participant This research received approval by the Ethics Committee of Shandong Mental Health Center, China. Measures Firstly, the data collection process involved using a self-administered questionnaire to gather basic information about the junior high school students. The questionnaire included items pertaining to gender (1 = male, 2 = female), age, grade, region, among others. Secondly, the outcome of this research is NSSI, assessed using the Adolescents Self-Harm Scale. The questionnaire used in this study was originally developed by Chinese scholars Zheng Ying et al. [51]. Previous research has demonstrated its good reliability and validity, making it a widely employed tool in Chinese studies on NSSI [52]. The questionnaire comprises 15 NSSI modalities, with an additional open-ended fill-in-the-blank question to assess the respondent’s NSSI status within the past year. Each modality is assessed based on the frequency and severity of self-injury. The frequency item has four response options (0–3), including 0, 1, 2–4 and ≥ 5 times, respectively. The severity item included 5 possible responses (0–4), representing “none,” “mild,” “moderate,” “severe” and “very severe,” respectively. The criteria defining the severity levels are detailed in the questionnaire’s introduction. The questionnaire demonstrated a Cronbach coefficient of 0.88, indicating good internal consistency. Thirdly, there are 17 factors used for prediction: anxiety score, depression score, five dimensions of personality traits, and ten dimensions of family environment. Anxiety was measured by the Self-Rating Anxiety Scale (SAS). This scale is a self-rated scale used to assess anxiety severity [53]. The scale consists of 20 items scored on a 4-point scale, with the participant choosing the appropriate option based on their symptoms. Five of the items are reverse scored. The scores for each question are summed and multiplied by 1.25 and rounded to obtain a standard score, and higher standardized scores indicate more severe anxiety. The Cronbach’s alpha for this questionnaire was 0.83 [54]. Depression was measured by the Self-Rating Depression Scale (SDS). This scale is a self-rated scale used to assess depression severity [55]. Similar to the SAS, the scale consists of 20 questions scored on a 4-point scale. Ten of the items are reverse scored. Also similar to the SAS, the scores of each question are summed and multiplied by 1.25 and rounded to the standard score, and the higher the standard score, the more severe the depression. The scale has a Cronbach’s alpha of 0.80 [54]. Personality traits was measured by the Neuroticism Extraversion Openness Five-Factor Inventory (NEO-FFI). The questionnaire was first developed in 1978 (NEO-PI) and was subsequently revised several times, resulting in a revised version called the NEO-FFI in 1992 that has been widely used in various countries today to measure personality traits [56]. The NEO-FFI questionnaire consists of five dimensions: neuroticism, extraversion, openness, agreeableness, and conscientiousness. It comprises a total of 60 items, all of which are scored on a 5-point scale (0–4), with 27 of the items reverse scored. The sum of the scores for each item represents the score for the corresponding dimension, with higher scores indicating more prominent characteristics in that particular dimension. Previous studies investigating Chinese high school student samples have reported internal consistency coefficients of 0.85, 0.80, 0.68, 0.75, and 0.83 for the neuroticism, extraversion, openness, agreeableness, and conscientiousness dimensions, respectively [57]. Family environment was measured by the Family Environment Scale-Chinese Version (FES-CV). The scale was originally developed by American psychologists Moos R. and Moos B [58]. After being revised by Chinese scholars, it has been widely used in China to assess the conditions and characteristics of different types of family environments. The scale consists of 90 questions, reflecting 10 dimensions of family cohesion, intellectual-culture, achievement, conflict, etc. Respondents choose “yes” or “no” to assess their own family situation, and the final analysis is based on the scores of the ten dimensions. The higher the score of each dimension, the more prominent the characteristics of the family. The Cronbach’s alpha for this questionnaire is 0.61. Data analyses As our research aim is to predict NSSI, we have employed the method of supervised machine learning. Firstly, after setting a random seed using R, random allocation was performed using the “createDataPartition” function in the caret package [59]. The rural sample was randomly divided into three sets: the train set (for establishing models), the valid set (for validing models), and the test set (for the final testing models). a training set comprising 70% of the data, a validation set consisting of 15%, and a testing set al.so comprising 15%. Secondly, to standardize the data in the training set, a z-score transformation (subtracting the mean µ from the original value and then dividing the result by the standard deviation δ) was employed. The µ and δ from the training set were saved for standardizing the validation and testing sets, ensuring that all the sets are standardized using the same mean and standard deviation [60]. Thirdly, the prediction models were constructed using R (Version 4.2.2). The construction of the SVM model utilized the e1071 package [61], which is a supervised machine learning tool primarily used for classification prediction [62] and includes four kernel functions (linear, radial, polynomial, sigmoid); the choice of kernel function directly impacts the classification performance of SVM [63]. The decision tree model was built using the rpart package [64], which constructs a tree-like tool consisting of decision nodes, branches, and leaf nodes to make predictions or classifications [65]. The random forest model was constructed using the randomForest package [66], which is a non-parametric ensemble machine learning method suitable for classification and regression prediction [67]. It is a collection of decision trees [67] known for its good performance and robustness [38]. The ggplot2 package [68] was utilized for visualizing the mean decrease Gini index. The models were established using the default hyperparameters provided by each package. Various metrics, such as sensitivity, specificity, AUC (area under the curve), accuracy, precision, and F1 score, were calculated to evaluate the performance of the models (refer to Fig. 2) [69, 70]. The process of training, validating, and testing the model is shown in Fig. 1. Fig. 2Assessment indicators calculation Assessment indicators calculation Finally, using the mean decrease Gini index [71, 72] to measure the mean decrease in node impurity to estimate the importance for NSSI relevant factors. Results Demographic characteristics In this study, a total of 2090 rural students participated, with an average age (SD) of 13.68 (0.991) and an NSSI prevalence of 38.3%. Among them, there were 1007 males (48.2%) with an average age (SD) of 13.72 (0.986) and 1083 females (51.8%) with an average age (SD) of 13.64 (0.995). The proportion of students in the first, second, and third grades of junior high school was 32.3%, 36.7%, and 31.0%, respectively. Building the prediction models based on machine learning We used gender, age, grade, and the relevant factors to establish a prediction model. The scores of factors across students with and without NSSI were shown in Table 2. Table 2Factor scores used to predict non-suicidal self-injury (NSSI)Factors (\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\overline{x}$$\end{document} ± SD)With NSSIWithout NSSIt/p-valueAnxiety46.55 ± 9.3639.36 ± 7.40-18.44/0.000Depression53.01 ± 10.5543.70 ± 9.77-20.53/0.000Neuroticism36.09 ± 4.0433.93 ± 4.15-11.68/0.000Extraversion37.22 ± 4.3337.86 ± 4.103.39/0.001Openness34.43 ± 4.8632.88 ± 4.81-7.12/0.000Agreeableness33.85 ± 4.0734.80 ± 3.885.33/0.000Conscientiousness36.60 ± 4.0937.97 ± 4.297.22/0.000Family Cohesion6.60 ± 2.437.79 ± 1.6912.16/0.000Family Expressiveness4.57 ± 1.735.14 ± 1.557.69/0.000Family Conflict3.52 ± 2.292.27 ± 1.87-12.99/0.000Family Independence4.80 ± 1.565.03 ± 1.453.35/0.001Family Achievement4.40 ± 1.474.61 ± 1.403.27/0.001Family Intellectual Culture3.47 ± 1.914.26 ± 2.108.79/0.000Family Active Recreational3.98 ± 2.444.97 ± 2.439.04/0.000Family Moral Religious5.49 ± 1.545.74 ± 1.363.77/0.000Family Organization5.50 ± 2.096.48 ± 1.8211.01/0.000Family Control3.47 ± 1.993.60 ± 1.991.50/0.133Legend The content of this table is a description of the score of each questionnaire for the group with and without NSSI Table 2Factor scores used to predict non-suicidal self-injury (NSSI)Factors (\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\overline{x}$$\end{document} ± SD)With NSSIWithout NSSIt/p-valueAnxiety46.55 ± 9.3639.36 ± 7.40-18.44/0.000Depression53.01 ± 10.5543.70 ± 9.77-20.53/0.000Neuroticism36.09 ± 4.0433.93 ± 4.15-11.68/0.000Extraversion37.22 ± 4.3337.86 ± 4.103.39/0.001Openness34.43 ± 4.8632.88 ± 4.81-7.12/0.000Agreeableness33.85 ± 4.0734.80 ± 3.885.33/0.000Conscientiousness36.60 ± 4.0937.97 ± 4.297.22/0.000Family Cohesion6.60 ± 2.437.79 ± 1.6912.16/0.000Family Expressiveness4.57 ± 1.735.14 ± 1.557.69/0.000Family Conflict3.52 ± 2.292.27 ± 1.87-12.99/0.000Family Independence4.80 ± 1.565.03 ± 1.453.35/0.001Family Achievement4.40 ± 1.474.61 ± 1.403.27/0.001Family Intellectual Culture3.47 ± 1.914.26 ± 2.108.79/0.000Family Active Recreational3.98 ± 2.444.97 ± 2.439.04/0.000Family Moral Religious5.49 ± 1.545.74 ± 1.363.77/0.000Family Organization5.50 ± 2.096.48 ± 1.8211.01/0.000Family Control3.47 ± 1.993.60 ± 1.991.50/0.133Legend The content of this table is a description of the score of each questionnaire for the group with and without NSSI Factor scores used to predict non-suicidal self-injury (NSSI) Legend The content of this table is a description of the score of each questionnaire for the group with and without NSSI We had established and validated each model by the train set and the validation set, metric shown in Table s1. Subsequently, we had tested each model by the test data, calculated the metrics (Table 3) and plotted ROC curves (Fig. 3). Upon examining the models, it was found that the models generated by the four kernel functions of SVM all showed noticeably poor metrics. While decision tree and random forest performed similarly in terms of sensitivity, specificity, accuracy, precision, and F1 score, the AUC of random forest was significantly better than decision tree, both in the valid and test set. Based on these results, it was determined that the random forest model was the most suitable model for this study. Table 3Metrics for each non-suicidal self-injury (NSSI) predictive model in the test setValueSupport vector machineDecision treeRandom forestLinearRadialPolynomialSigmoidSensitivity0.320.260.340.540.590.65Specificity0.330.450.440.230.760.72AUC0.760.730.670.640.690.76Accuracy0.330.380.400.340.700.70Precision0.220.220.260.290.580.57F1 Score0.260.240.290.370.590.61Legend The contents of this table are metrics for model testing (using the test set) Table 3Metrics for each non-suicidal self-injury (NSSI) predictive model in the test setValueSupport vector machineDecision treeRandom forestLinearRadialPolynomialSigmoidSensitivity0.320.260.340.540.590.65Specificity0.330.450.440.230.760.72AUC0.760.730.670.640.690.76Accuracy0.330.380.400.340.700.70Precision0.220.220.260.290.580.57F1 Score0.260.240.290.370.590.61Legend The contents of this table are metrics for model testing (using the test set) Metrics for each non-suicidal self-injury (NSSI) predictive model in the test set Legend The contents of this table are metrics for model testing (using the test set) Fig. 3ROC of each model in the test set ROC of each model in the test set Calculation of the mean decrease Gini index for each factor After identifying random forest as the suitable model for predicting the prevalence of NSSI, we calculated the mean decrease Gini index (for measuring the mean decrease in node impurity) to estimate the importance of NSSI-relevant factors. In the results, we found that the main factors involved in the prediction were depression and anxiety. Neuroticism was the most significant predictive factor among personality traits, and conflict was the most significant predictive factor in the family environment. However, considering the ranking of these variables and Mean Decrease Gini, neuroticism and conflict may play a relatively minor role in the prediction. In addition, demographic factors contributed little to the prediction in this study (refer to Fig. 4). Fig. 4Mean decrease Gini index for each factor Mean decrease Gini index for each factor Discussion This research study offers a suitable model for predicting NSSI in Chinese rural children and adolescents. It also validates the importance of NSSI-relevant factors. Among all models that were compared, the random forest model proved to be the most appropriate in this research. The random forest model is an ensemble of decision trees, using multiple decision trees for training and validation of data, which helps to avoid overfitting issues commonly associated with individual decision trees and improve predictive performance [71]. Current medical data processing often involves large datasets, and random forest is a combination of bagging algorithm and random subspace [73], making it one of the most successful machine learning techniques for large data classification and handling skewed problems [74]. In our study, this model allows for the identification of a greater number of individuals who may be at risk for NSSI, which can aid in subsequent targeted screening conducted by professionals. The prevalence of NSSI among rural junior high school students in this study was found to be 38.3%, which is higher than what has been reported in previous studies conducted in China [75]. There is considerable variation in the prevalence of NSSI reported across different studies in the international literature. This variation can be attributed to differences in sample characteristics, such as studies conducted among clinically depressed patients or in the general population. Furthermore, different criteria and rating instruments for assessing NSSI may contribute to the discrepancies. A meta-analysis, encompassing 680,000 young individuals from various parts of the world revealed that the incidence of NSSI in their lifetime was found to be 22.1%. Specifically, the prevalence in Western countries was 19.4%, whereas non-Western countries reported a higher prevalence of 32.6%. Further subgroup analysis, differentiating between developed and developing countries, indicated a lifetime prevalence of 20.0% in developed countries and 33.7% in developing countries [76]. By considering the syntheses of prior studies, the observed NSSI prevalence in our research aligns with the documented rates in non-Western and developing countries, leading us to regard the results of this study as more dependable. Upon conducting the prediction model estimation and relevant factor importance analysis, it was observed that depression and anxiety persist as the most impactful factors contributing to the incidence of NSSI. Fliege et al. [77] noted in their study that individuals who engage in NSSI tend to experience more negative emotions, such as anxiety and depression, compared to those who do not engage in NSSI. These negative emotions, identified as the primary personal factors with the strongest evidence of influencing NSSI, can potentially influence an individual’s behavioral responses [78] and potentially lead to increased NSSI. Furthermore, it has been suggested that individuals with depression and anxiety are more inclined to engage in NSSI as a means of alleviating these negative emotions [79], aligning with the concept of negative self-reinforcement (self-injury as a method to alleviate negative emotions) in the four-function model discussed earlier. Our study compared the degree of influence of depression and anxiety with personality traits and family environment on NSSI and found that among these types of factors, timely interventions for individuals with existing emotional and psychological problems may have better results in reducing the occurrence of NSSI. In terms of the contribution to the predictive model, among the five dimensions of personality traits, particularly neuroticism, it ranked second only to depression and anxiety, which aligns with the findings of previous studies [80]. Grandclerc et al. [14] mentioned in their study that individuals who exhibit characteristics such as impulsivity and aggression during early developmental stages are more prone to developing NSSI. Behaviors such as impulsivity are manifestations of neuroticism. Previous studies have found that a typical characteristic of neuroticism is negative emotions [81], which is not only reflected in higher levels of negative emotions but also in greater emotional variability [82, 83]. Some researchers even use the term emotional stability as the opposite of neuroticism [84]. Individuals with high levels of neuroticism may exhibit characteristics such as emotional instability, anxiety, and irritability [85] as well as an increased likelihood of experiencing negative life events [86]. These individuals are more likely to experience greater negative impacts when faced with adversities in life [87] and are more susceptible to experiencing depressive symptoms or psychological distress [88, 89]. This may exacerbate the distress caused by negative events and lead to more issues for them. Previous studies have also highlighted the phenomenon of social transmission [90], indicating that groups characterized by openness to external influences are more likely to engage in socially transmitted behaviors. This may explain why openness is ranked fourth in terms of contribution. However, considering the rankings of neuroticism and openness and their Mean Decrease Gini values, these two dimensions have a relatively minor role in predicting NSSI. The influence of family environment on NSSI is mainly in conflict. Shao et al. found in their study that individuals engaging in NSSI experience a decrease in interpersonal functioning and impaired family cohesion [91], which may lead to more family conflicts. The increase in family conflicts inevitably brings negative emotional experiences to individuals. According to the experiential avoidance model of self-harm proposed by Chapman et al. [92], when individuals face these negative emotional experiences, they may resort to NSSI as a way of escape. Research has also shown that adolescents from discordant families are more likely to exhibit higher levels of aggression and engage in NSSI [93]. Furthermore, families with more conflicts may struggle to provide children with an adequate sense of safety and trust, and a lack of security and trust may also be one of the reasons influencing the development of mental health and behavioral problems in youth [93]. The above study also echoes the main problem between rural families in China today: Due to the economic disparity between urban and rural areas, a significant number of rural laborers migrate to cities for work, often leaving their children in rural areas to reduce the financial burden in urban settings [48]. This results in unstable family structures for these children and adolescents, potentially leading to more behavioral issues [94]. However, it is essential to note that considering the ranking of conflict in terms of contribution, its role in predicting NSSI may have been overestimated. This study possesses several strengths. Firstly, it surveyed a large sample of Chinese rural junior high school students, which enhances the generalizability of the findings. Secondly, an appropriate model was selected and the importance of relevant factors was calculated, ensuring a robust analysis. Additionally, there is a scarcity of previous studies utilizing machine learning models to predict NSSI in Chinese rural children and adolescents, making this study a valuable addition to the existing literature in this field. This study has several limitations. In terms of research methods, firstly, it is a cross-sectional self-assessment questionnaire survey, which may be subjective and biased. Secondly, the sample was selected using convenience sampling, which may introduce bias in the selection process. Thirdly, the predictive factors included in this study are relatively limited, considering only the family environment as an external factor. Fourthly, both the predictive and outcome indicators were measured by questionnaires, which introduces certain limitations to the predictions. The selection of the sample and research methods significantly affect the generalizability of the findings. Therefore, future studies should aim to collect more longitudinal data to supplement the research content and analyze causal relationships. Additionally, a more representative random sampling method should be employed to enhance the generalizability of the conclusions. Moreover, incorporating more comprehensive predictive factors can help avoid exaggerating non-specific associations due to loose factors. Lastly, outcome indicators should, whenever possible, be clarified using structured or semi-structured interviews to prevent outcomes from being obscured or exaggerated due to personal factors. In terms of research content, all factors used for prediction were collected simultaneously, which may lead to potential interrelationships between variables, such as anxiety and depression. Currently, mental disorders remain complex conditions with unclear etiology and pathology. Although many studies have attempted to elucidate the risk and protective factors of these disorders, the contribution of any single factor is often minimal [95]. Thus, mental disorders may result from the combined influence of multiple factors. In this study, NSSI often does not occur in isolation; emotional issues such as anxiety and depression may coexist with and exacerbate the development of NSSI. This indicates that we need to identify causal relationships through longitudinal studies between different disorders and between disorders and influencing factors. Additionally, we should broaden the scope of included factors to provide a more comprehensive and accurate description of the impact network of mental disorders through multimodal measurements of risk factors (such as incorporating blood indicators, neuroelectrophysiological indicators, and brain imaging indicators). Reliable and stable conclusions can provide theoretical guidance for clinical interventions in mental health issues. For disorders where a single factor contributes significantly, we can focus our interventions to quickly improve outcomes while reducing treatment costs. Conversely, for disorders where multiple factors contribute minimally, a comprehensive intervention from multiple perspectives is needed to ensure effective treatment while preventing relapse. Conclusion This study focused on Chinese children and adolescents in rural areas and demonstrated the potential of using the machine learning approach in predicting NSSI. Our research complements the application of machine learning methods to psychiatric and psychological problems. Electronic supplementary material Below is the link to the electronic supplementary material. Supplementary Material 1 Supplementary Material 1