date()
## [1] "Sat May  3 10:54:21 2025"
options(scipen = 999)

libraries

library(kableExtra)
library(reshape2)
library(ggplot2)
library(dplyr)
## 
## Присоединяю пакет: 'dplyr'
## Следующий объект скрыт от 'package:kableExtra':
## 
##     group_rows
## Следующие объекты скрыты от 'package:stats':
## 
##     filter, lag
## Следующие объекты скрыты от 'package:base':
## 
##     intersect, setdiff, setequal, union
library(stats)
library(tidyr)
## 
## Присоединяю пакет: 'tidyr'
## Следующий объект скрыт от 'package:reshape2':
## 
##     smiths
library(readxl)
library(psych)
## Warning: пакет 'psych' был собран под R версии 4.3.3
## 
## Присоединяю пакет: 'psych'
## Следующие объекты скрыты от 'package:ggplot2':
## 
##     %+%, alpha
library(corrplot)
## Warning: пакет 'corrplot' был собран под R версии 4.3.3
## corrplot 0.95 loaded
margo <- read_excel("Margo_full.xlsx")
margo$Sex <- factor(margo$Sex, levels = c(1, 2), labels = c("Male", 'Female'), ordered = FALSE)       
margo$Range <- factor(margo$Range, levels = c(1:3), ordered = TRUE, labels = c("1,2 razryad",
                                                                               'kms',
                                                                               'ms'))
margo$Discipline <- factor(margo$Discipline, levels = c('Пистолет','Винтовка'), ordered = TRUE, labels = c("Pistol",'Vint'))
#margo$Samoobl_Personal_N <- factor(margo$Samoobl_Personal_N, levels = c('высокий','средний','низкий'), ordered = FALSE, labels = c('Large', 'Medium', 'Small'))

female <- subset(margo, Sex == 'Female')
male <- subset(margo, Sex == 'Male')
razryad <- subset(margo, Range == '1,2 razryad')
kms <- subset(margo, Range == 'kms')
ms <- subset(margo, Range == 'ms')
summary(margo)
##      Sex           Age          Experience      Discipline         Range   
##  Male  : 52   Min.   :12.00   Min.   : 1.000   Pistol:73   1,2 razryad:56  
##  Female:118   1st Qu.:15.25   1st Qu.: 3.250   Vint  :97   kms        :43  
##               Median :18.00   Median : 6.000               ms         :71  
##               Mean   :19.99   Mean   : 7.294                               
##               3rd Qu.:22.00   3rd Qu.: 9.750                               
##               Max.   :50.00   Max.   :37.000                               
##     S_Moral         S_Coping        S_Values     S_StressGrowth 
##  Min.   :13.00   Min.   :12.00   Min.   :13.00   Min.   :17.00  
##  1st Qu.:30.00   1st Qu.:29.00   1st Qu.:33.00   1st Qu.:35.00  
##  Median :35.00   Median :35.00   Median :38.00   Median :41.00  
##  Mean   :34.99   Mean   :34.34   Mean   :37.37   Mean   :39.03  
##  3rd Qu.:41.00   3rd Qu.:41.00   3rd Qu.:42.00   3rd Qu.:45.00  
##  Max.   :49.00   Max.   :49.00   Max.   :49.00   Max.   :49.00  
##     S_Index      Samoobl_Personal_Q Samoobl_Personal_N Samoobl_Event_Q 
##  Min.   : 56.0   Min.   : 3.00      Length:170         Min.   : 2.000  
##  1st Qu.:130.0   1st Qu.:13.25      Class :character   1st Qu.: 8.000  
##  Median :146.5   Median :16.00      Mode  :character   Median :10.000  
##  Mean   :145.7   Mean   :15.69                         Mean   : 9.941  
##  3rd Qu.:165.0   3rd Qu.:18.00                         3rd Qu.:12.000  
##  Max.   :192.0   Max.   :21.00                         Max.   :14.000  
##  Samoobl_Event_N    Samoobl_Exist_Q Samoobl_Exist_N    Samoobl_Index_Q
##  Length:170         Min.   : 2.00   Length:170         Min.   : 7.00  
##  Class :character   1st Qu.: 8.00   Class :character   1st Qu.:31.25  
##  Mode  :character   Median :10.00   Mode  :character   Median :36.00  
##                     Mean   :10.09                      Mean   :35.72  
##                     3rd Qu.:12.00                      3rd Qu.:41.00  
##                     Max.   :14.00                      Max.   :49.00  
##  Samoobl_Index_N      Anxiety_Q      Anxiety_N          Prochnost_Q   
##  Length:170         Min.   :10.00   Length:170         Min.   :12.00  
##  Class :character   1st Qu.:16.00   Class :character   1st Qu.:41.00  
##  Mode  :character   Median :18.00   Mode  :character   Median :44.00  
##                     Mean   :18.84                      Mean   :43.32  
##                     3rd Qu.:22.00                      3rd Qu.:48.00  
##                     Max.   :30.00                      Max.   :55.00  
##  Prochnost_N         Zh_Vovlech_Q   Zh_Vovlech_N        Zh_Control_Q  
##  Length:170         Min.   : 6.00   Length:170         Min.   : 5.00  
##  Class :character   1st Qu.:10.00   Class :character   1st Qu.:11.00  
##  Mode  :character   Median :11.00   Mode  :character   Median :12.00  
##                     Mean   :11.44                      Mean   :12.15  
##                     3rd Qu.:13.00                      3rd Qu.:13.00  
##                     Max.   :16.00                      Max.   :16.00  
##  Zh_Control_N       Zh_Acceptance_Q Zh_Acceptance_N      Zh_Index_Q   
##  Length:170         Min.   : 6.00   Length:170         Min.   :22.00  
##  Class :character   1st Qu.: 9.00   Class :character   1st Qu.:31.00  
##  Mode  :character   Median :10.00   Mode  :character   Median :34.00  
##                     Mean   :10.04                      Mean   :33.64  
##                     3rd Qu.:11.00                      3rd Qu.:37.00  
##                     Max.   :14.00                      Max.   :46.00  
##   Zh_Index_N          Resilience   
##  Length:170         Min.   : 6.00  
##  Class :character   1st Qu.:18.00  
##  Mode  :character   Median :20.00  
##                     Mean   :20.21  
##                     3rd Qu.:23.00  
##                     Max.   :30.00

корреляция

numeric_data <- margo[sapply(margo, is.numeric)]

correlation_matrix <- cor(numeric_data) 
p_values <- matrix(NA, nrow = ncol(numeric_data), ncol = ncol(numeric_data))
rownames(p_values) <- colnames(p_values) <- colnames(numeric_data)
for (i in 1:(ncol(numeric_data) - 1)) {
  for (j in (i + 1):ncol(numeric_data)) {
    cor_test_result <- cor.test(numeric_data[[i]], numeric_data[[j]])
    p_values[i, j] <- p_values[j, i] <- cor_test_result$p.value
  }
}

significant_level <- 0.05
significant <- ifelse(p_values < significant_level, "*", "")

cor_matrix_with_significance <- round(correlation_matrix, 2)
cor_matrix_with_significance[lower.tri(cor_matrix_with_significance)] <- paste(cor_matrix_with_significance[lower.tri(cor_matrix_with_significance)], significant[lower.tri(significant)], sep = "")

cor_thes <- as.data.frame(cor_matrix_with_significance)
cor_thes <- cor_thes[-1, -1]
kable(cor_thes, format = "html") %>%
  kable_styling()
Experience S_Moral S_Coping S_Values S_StressGrowth S_Index Samoobl_Personal_Q Samoobl_Event_Q Samoobl_Exist_Q Samoobl_Index_Q Anxiety_Q Prochnost_Q Zh_Vovlech_Q Zh_Control_Q Zh_Acceptance_Q Zh_Index_Q Resilience
Experience 1 0.16 0.12 0.04 0.07 0.11 0.1 0.13 0.19 0.16 -0.12 -0.03 0.05 -0.02 -0.08 -0.01 0.05
S_Moral 0.16* 1 0.64 0.7 0.67 0.86 0.37 0.4 0.55 0.51 -0.29 0.09 0.23 0.17 0.12 0.24 0.32
S_Coping 0.12 0.64* 1 0.71 0.68 0.88 0.47 0.61 0.47 0.62 -0.54 0.27 0.36 0.22 0.24 0.38 0.55
S_Values 0.04 0.7* 0.71* 1 0.68 0.88 0.36 0.44 0.52 0.51 -0.3 0.16 0.36 0.25 0.18 0.37 0.34
S_StressGrowth 0.07 0.67* 0.68* 0.68* 1 0.87 0.35 0.47 0.44 0.49 -0.44 0.2 0.28 0.27 0.11 0.31 0.43
S_Index 0.11 0.86* 0.88* 0.88* 0.87* 1 0.45 0.56 0.56 0.62 -0.46 0.21 0.35 0.26 0.19 0.37 0.48
Samoobl_Personal_Q 0.1 0.37* 0.47* 0.36* 0.35* 0.45* 1 0.58 0.51 0.89 -0.34 0.29 0.18 0.14 0.2 0.23 0.5
Samoobl_Event_Q 0.13 0.4* 0.61* 0.44* 0.47* 0.56* 0.58* 1 0.48 0.81 -0.42 0.35 0.21 0.17 0.2 0.26 0.46
Samoobl_Exist_Q 0.19* 0.55* 0.47* 0.52* 0.44* 0.56* 0.51* 0.48* 1 0.77 -0.33 0.22 0.26 0.23 0.06 0.26 0.33
Samoobl_Index_Q 0.16* 0.51* 0.62* 0.51* 0.49* 0.62* 0.89* 0.81* 0.77* 1 -0.43 0.35 0.25 0.21 0.19 0.3 0.53
Anxiety_Q -0.12 -0.29* -0.54* -0.3* -0.44* -0.46* -0.34* -0.42* -0.33* -0.43* 1 -0.17 -0.3 -0.27 -0.14 -0.33 -0.55
Prochnost_Q -0.03 0.09 0.27* 0.16* 0.2* 0.21* 0.29* 0.35* 0.22* 0.35* -0.17* 1 0.24 0.28 0.09 0.29 0.3
Zh_Vovlech_Q 0.05 0.23* 0.36* 0.36* 0.28* 0.35* 0.18* 0.21* 0.26* 0.25* -0.3* 0.24* 1 0.46 0.29 0.84 0.22
Zh_Control_Q -0.02 0.17* 0.22* 0.25* 0.27* 0.26* 0.14 0.17* 0.23* 0.21* -0.27* 0.28* 0.46* 1 0.16 0.75 0.23
Zh_Acceptance_Q -0.08 0.12 0.24* 0.18* 0.11 0.19* 0.2* 0.2* 0.06 0.19* -0.14 0.09 0.29* 0.16* 1 0.6 0.14
Zh_Index_Q -0.01 0.24* 0.38* 0.37* 0.31* 0.37* 0.23* 0.26* 0.26* 0.3* -0.33* 0.29* 0.84* 0.75* 0.6* 1 0.27
Resilience 0.05 0.32* 0.55* 0.34* 0.43* 0.48* 0.5* 0.46* 0.33* 0.53* -0.55* 0.3* 0.22* 0.23* 0.14 0.27* 1

корреляция красивая!

selected_vars <- margo[, c(2, 3, 6:10, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31)]

numeric_data <- selected_vars[sapply(selected_vars, is.numeric)]


corPlot(
  numeric_data,
  stars = TRUE,
  MAR = 4,
  xlas = 2,
  cex = 0.6,  # уменьшение размера шрифта подписей
  labels = c(
    "Взр", "Ст", "МВУ", "СтрС", "ЦСм", "ПТР", "ПБЛ",
    "ЛС", "СС", "ЭС", "ОС", "Тр", "МП", "В", "К",
    "Пр", "Ж", "Р"
  )
)

дисперсии

data_list <- list(razryad$Samoobl_Index_Q, kms$Samoobl_Exist_Q, ms$Samoobl_Index_Q)
boxplot(data_list, names = c("12", "кмс", "мс"), main = "", xlab = "Разряд", ylab = "Тревожность")

регрессия

model <- lm(S_Index ~ Age + Experience + Samoobl_Index_Q + Range + Anxiety_Q + Prochnost_Q + Zh_Index_Q + Resilience +Discipline , data = margo)
final_model <- step(model)
## Start:  AIC=1023.27
## S_Index ~ Age + Experience + Samoobl_Index_Q + Range + Anxiety_Q + 
##     Prochnost_Q + Zh_Index_Q + Resilience + Discipline
## 
##                   Df Sum of Sq   RSS    AIC
## - Discipline       1      41.3 61471 1021.4
## - Experience       1      82.6 61512 1021.5
## - Prochnost_Q      1     435.1 61865 1022.5
## <none>                         61430 1023.3
## - Resilience       1     782.0 62212 1023.4
## - Age              1     994.3 62424 1024.0
## - Range            2    2099.6 63529 1025.0
## - Zh_Index_Q       1    1978.8 63409 1026.7
## - Anxiety_Q        1    2476.6 63906 1028.0
## - Samoobl_Index_Q  1   15440.5 76870 1059.4
## 
## Step:  AIC=1021.39
## S_Index ~ Age + Experience + Samoobl_Index_Q + Range + Anxiety_Q + 
##     Prochnost_Q + Zh_Index_Q + Resilience
## 
##                   Df Sum of Sq   RSS    AIC
## - Experience       1      75.6 61547 1019.6
## - Prochnost_Q      1     451.2 61922 1020.6
## <none>                         61471 1021.4
## - Resilience       1     835.6 62307 1021.7
## - Age              1    1015.2 62486 1022.2
## - Range            2    2160.4 63632 1023.3
## - Zh_Index_Q       1    2096.3 63567 1025.1
## - Anxiety_Q        1    2435.7 63907 1026.0
## - Samoobl_Index_Q  1   15404.3 76875 1057.4
## 
## Step:  AIC=1019.6
## S_Index ~ Age + Samoobl_Index_Q + Range + Anxiety_Q + Prochnost_Q + 
##     Zh_Index_Q + Resilience
## 
##                   Df Sum of Sq   RSS    AIC
## - Prochnost_Q      1     435.2 61982 1018.8
## <none>                         61547 1019.6
## - Resilience       1     868.0 62415 1020.0
## - Age              1    1571.5 63118 1021.9
## - Range            2    2506.0 64053 1022.4
## - Zh_Index_Q       1    2228.7 63775 1023.6
## - Anxiety_Q        1    2368.9 63916 1024.0
## - Samoobl_Index_Q  1   15328.8 76876 1055.4
## 
## Step:  AIC=1018.8
## S_Index ~ Age + Samoobl_Index_Q + Range + Anxiety_Q + Zh_Index_Q + 
##     Resilience
## 
##                   Df Sum of Sq   RSS    AIC
## - Resilience       1     722.7 62705 1018.8
## <none>                         61982 1018.8
## - Range            2    2347.9 64330 1021.1
## - Age              1    1647.3 63629 1021.3
## - Zh_Index_Q       1    1943.1 63925 1022.0
## - Anxiety_Q        1    2499.0 64481 1023.5
## - Samoobl_Index_Q  1   14948.5 76931 1053.5
## 
## Step:  AIC=1018.77
## S_Index ~ Age + Samoobl_Index_Q + Range + Anxiety_Q + Zh_Index_Q
## 
##                   Df Sum of Sq   RSS    AIC
## <none>                         62705 1018.8
## - Age              1    1739.4 64444 1021.4
## - Range            2    2693.4 65398 1021.9
## - Zh_Index_Q       1    2030.3 64735 1022.2
## - Anxiety_Q        1    4444.1 67149 1028.4
## - Samoobl_Index_Q  1   20360.7 83065 1064.6
summary(final_model)
## 
## Call:
## lm(formula = S_Index ~ Age + Samoobl_Index_Q + Range + Anxiety_Q + 
##     Zh_Index_Q, data = margo)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -61.955  -9.255   0.828  10.913  67.591 
## 
## Coefficients:
##                 Estimate Std. Error t value        Pr(>|t|)    
## (Intercept)      73.6369    19.1897   3.837        0.000178 ***
## Age               0.5123     0.2409   2.126        0.034976 *  
## Samoobl_Index_Q   1.6428     0.2258   7.275 0.0000000000138 ***
## Range.L          -6.1680     2.7945  -2.207        0.028697 *  
## Range.Q          -4.3361     2.9054  -1.492        0.137524    
## Anxiety_Q        -1.4042     0.4131  -3.399        0.000851 ***
## Zh_Index_Q        0.9050     0.3940   2.297        0.022872 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 19.61 on 163 degrees of freedom
## Multiple R-squared:  0.4757, Adjusted R-squared:  0.4564 
## F-statistic: 24.65 on 6 and 163 DF,  p-value: < 0.00000000000000022