R Markdown

rm(list = ls())

#LOAD LIBRARIES

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(psych)
library(ggplot2)
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
library(readxl)
data1<-read_excel("C:/Users/USER/OneDrive/Documents/jkia_delayed_payments_survey_150_filtered.....new.xlsx")
# Create Composite Scores

data1 <- data1 %>%
  mutate(
    compliance_score   = rowMeans(select(., Compliance_Report_Work,
                                         Compliance_Follow_Instructions,
                                         Compliance_Fear_Job_Loss), na.rm = TRUE),
    morale_score       = rowMeans(select(., Morale_Job_Satisfaction,
                                         Morale_Stress_Anxiety,
                                         Morale_Motivation,
                                         Morale_Seek_Other_Employment), na.rm = TRUE),
    productivity_score = rowMeans(select(., Productivity_Quality,
                                         Productivity_Pace,
                                         Productivity_Sick_Days), na.rm = TRUE)
  )
# 4. Descriptive Statistics
summary_stats <- data1 %>%
  summarise(
    mean_compliance   = mean(compliance_score, na.rm = TRUE),
    mean_morale       = mean(morale_score, na.rm = TRUE),
    mean_productivity = mean(productivity_score, na.rm = TRUE)
  )
#Reliability Checks (Cronbach's alpha)
psych::alpha(dplyr::select(data1, Compliance_Report_Work,
                                 Compliance_Follow_Instructions,
                                 Compliance_Fear_Job_Loss))
## Warning in psych::alpha(dplyr::select(data1, Compliance_Report_Work, Compliance_Follow_Instructions, : Some items were negatively correlated with the first principal component and probably 
## should be reversed.  
## To do this, run the function again with the 'check.keys=TRUE' option
## Some items ( Compliance_Follow_Instructions ) were negatively correlated with the first principal component and 
## probably should be reversed.  
## To do this, run the function again with the 'check.keys=TRUE' option
## Warning in sqrt(Vtc): NaNs produced
## 
## Reliability analysis   
## Call: psych::alpha(x = dplyr::select(data1, Compliance_Report_Work, 
##     Compliance_Follow_Instructions, Compliance_Fear_Job_Loss))
## 
##   raw_alpha std.alpha G6(smc) average_r    S/N  ase mean   sd median_r
##     -0.064    -0.065  -0.037    -0.021 -0.061 0.15    3 0.82   -0.013
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt    -0.40 -0.06  0.20
## Duhachek -0.36 -0.06  0.23
## 
##  Reliability if an item is dropped:
##                                raw_alpha std.alpha G6(smc) average_r    S/N
## Compliance_Report_Work            -0.200    -0.200  -0.091    -0.091 -0.167
## Compliance_Follow_Instructions     0.078     0.079   0.041     0.041  0.085
## Compliance_Fear_Job_Loss          -0.026    -0.026  -0.013    -0.013 -0.025
##                                alpha se var.r  med.r
## Compliance_Report_Work             0.20    NA -0.091
## Compliance_Follow_Instructions     0.15    NA  0.041
## Compliance_Fear_Job_Loss           0.17    NA -0.013
## 
##  Item statistics 
##                                  n raw.r std.r r.cor r.drop mean  sd
## Compliance_Report_Work         150  0.62  0.61   NaN  0.020  3.1 1.5
## Compliance_Follow_Instructions 150  0.53  0.53   NaN -0.070  3.0 1.5
## Compliance_Fear_Job_Loss       150  0.55  0.56   NaN -0.035  2.9 1.4
## 
## Non missing response frequency for each item
##                                   1    2    3    4    5 miss
## Compliance_Report_Work         0.21 0.18 0.19 0.17 0.25    0
## Compliance_Follow_Instructions 0.22 0.18 0.19 0.20 0.21    0
## Compliance_Fear_Job_Loss       0.21 0.23 0.17 0.22 0.18    0
psych::alpha(dplyr::select(data1, Morale_Job_Satisfaction,
                                 Morale_Stress_Anxiety,
                                 Morale_Motivation,
                                 Morale_Seek_Other_Employment))
## Warning in psych::alpha(dplyr::select(data1, Morale_Job_Satisfaction, Morale_Stress_Anxiety, : Some items were negatively correlated with the first principal component and probably 
## should be reversed.  
## To do this, run the function again with the 'check.keys=TRUE' option
## Some items ( Morale_Job_Satisfaction Morale_Seek_Other_Employment ) were negatively correlated with the first principal component and 
## probably should be reversed.  
## To do this, run the function again with the 'check.keys=TRUE' option
## Warning in sqrt(Vtc): NaNs produced
## 
## Reliability analysis   
## Call: psych::alpha(x = dplyr::select(data1, Morale_Job_Satisfaction, 
##     Morale_Stress_Anxiety, Morale_Motivation, Morale_Seek_Other_Employment))
## 
##   raw_alpha std.alpha G6(smc) average_r    S/N  ase mean   sd median_r
##     -0.072    -0.074  -0.042    -0.017 -0.069 0.14    3 0.69   -0.025
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt    -0.38 -0.07  0.18
## Duhachek -0.35 -0.07  0.21
## 
##  Reliability if an item is dropped:
##                              raw_alpha std.alpha G6(smc) average_r     S/N
## Morale_Job_Satisfaction        0.00074    0.0030  0.0105   0.00099  0.0030
## Morale_Stress_Anxiety         -0.00637   -0.0078 -0.0024  -0.00259 -0.0077
## Morale_Motivation             -0.14926   -0.1501 -0.0877  -0.04548 -0.1305
## Morale_Seek_Other_Employment  -0.06754   -0.0711 -0.0350  -0.02264 -0.0664
##                              alpha se  var.r    med.r
## Morale_Job_Satisfaction          0.14 0.0064  0.00091
## Morale_Stress_Anxiety            0.14 0.0021  0.00091
## Morale_Motivation                0.16 0.0057 -0.07887
## Morale_Seek_Other_Employment     0.15 0.0086 -0.04999
## 
##  Item statistics 
##                                n raw.r std.r r.cor r.drop mean  sd
## Morale_Job_Satisfaction      150  0.44  0.46   NaN -0.061  2.8 1.4
## Morale_Stress_Anxiety        150  0.46  0.46   NaN -0.056  3.0 1.4
## Morale_Motivation            150  0.53  0.53   NaN  0.020  2.9 1.4
## Morale_Seek_Other_Employment 150  0.51  0.49   NaN -0.023  3.1 1.5
## 
## Non missing response frequency for each item
##                                 1    2    3    4    5 miss
## Morale_Job_Satisfaction      0.22 0.25 0.21 0.17 0.15    0
## Morale_Stress_Anxiety        0.17 0.25 0.17 0.19 0.21    0
## Morale_Motivation            0.23 0.17 0.22 0.21 0.17    0
## Morale_Seek_Other_Employment 0.19 0.21 0.16 0.21 0.24    0
psych::alpha(dplyr::select(data1, Productivity_Quality,
                                 Productivity_Pace,
                                 Productivity_Sick_Days))
## 
## Reliability analysis   
## Call: psych::alpha(x = dplyr::select(data1, Productivity_Quality, Productivity_Pace, 
##     Productivity_Sick_Days))
## 
##   raw_alpha std.alpha G6(smc) average_r  S/N  ase mean   sd median_r
##       0.21      0.21    0.15     0.081 0.26 0.11  2.9 0.89    0.088
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt    -0.04  0.21  0.41
## Duhachek -0.01  0.21  0.43
## 
##  Reliability if an item is dropped:
##                        raw_alpha std.alpha G6(smc) average_r   S/N alpha se
## Productivity_Quality       0.162     0.162   0.088     0.088 0.193     0.14
## Productivity_Pace          0.241     0.241   0.137     0.137 0.318     0.12
## Productivity_Sick_Days     0.034     0.034   0.018     0.018 0.036     0.16
##                        var.r med.r
## Productivity_Quality      NA 0.088
## Productivity_Pace         NA 0.137
## Productivity_Sick_Days    NA 0.018
## 
##  Item statistics 
##                          n raw.r std.r r.cor r.drop mean  sd
## Productivity_Quality   150  0.63  0.62  0.24   0.11  3.0 1.4
## Productivity_Pace      150  0.58  0.59  0.15   0.07  2.7 1.4
## Productivity_Sick_Days 150  0.66  0.66  0.34   0.16  2.9 1.5
## 
## Non missing response frequency for each item
##                           1    2    3    4    5 miss
## Productivity_Quality   0.21 0.21 0.15 0.22 0.21    0
## Productivity_Pace      0.23 0.28 0.16 0.17 0.15    0
## Productivity_Sick_Days 0.21 0.21 0.22 0.13 0.23    0
colnames(data1)
##  [1] "Gender"                         "Age Group"                     
##  [3] "Education Level"                "Employment Type"               
##  [5] "Department"                     "Length of Service"             
##  [7] "Delayed Payment Frequency"      "Average Delay"                 
##  [9] "Main Reason for Delay"          "Compliance_Report_Work"        
## [11] "Compliance_Follow_Instructions" "Compliance_Fear_Job_Loss"      
## [13] "Morale_Job_Satisfaction"        "Morale_Stress_Anxiety"         
## [15] "Morale_Motivation"              "Morale_Seek_Other_Employment"  
## [17] "Productivity_Quality"           "Productivity_Pace"             
## [19] "Productivity_Sick_Days"         "Coping Mechanisms"             
## [21] "Additional Comments"            "compliance_score"              
## [23] "morale_score"                   "productivity_score"
# Convert delay frequency and average delay into ordered numeric scales
data1 <- data1 %>%
  mutate(
    delay_freq_num = case_when(
      `Delayed Payment Frequency` == "Never" ~ 0,
      `Delayed Payment Frequency` == "Once" ~ 1,
       `Delayed Payment Frequency` == "2–3 times" ~ 2,
      `Delayed Payment Frequency` == "More than 3 times" ~ 3,
      TRUE ~ NA_real_
    ),
    delay_duration_num = case_when(
      `Average Delay` == "Less than 1 week" ~ 1,
      `Average Delay` == "1–2 weeks" ~ 2,
      `Average Delay` == "3–4 weeks" ~ 3,
      `Average Delay` == "More than a month" ~ 4,
      TRUE ~ NA_real_
    )
  )
cor_matrix <- cor(select(data1, delay_freq_num, delay_duration_num,
                         compliance_score, morale_score, productivity_score),
                  use = "pairwise.complete.obs")
print(cor_matrix)
##                    delay_freq_num delay_duration_num compliance_score
## delay_freq_num         1.00000000         0.07307102      0.141696120
## delay_duration_num     0.07307102         1.00000000      0.066559437
## compliance_score       0.14169612         0.06655944      1.000000000
## morale_score          -0.08793300         0.01267160      0.039344076
## productivity_score    -0.06395307         0.10647704     -0.009568297
##                    morale_score productivity_score
## delay_freq_num      -0.08793300       -0.063953075
## delay_duration_num   0.01267160        0.106477037
## compliance_score     0.03934408       -0.009568297
## morale_score         1.00000000        0.067319329
## productivity_score   0.06731933        1.000000000
# 8. Regression Models
model_compliance <- lm(compliance_score ~ delay_freq_num + delay_duration_num, data = data1)
model_morale     <- lm(morale_score ~ delay_freq_num + delay_duration_num, data = data1)
model_product    <- lm(productivity_score ~ delay_freq_num + delay_duration_num, data = data1)
summary(model_compliance)
## 
## Call:
## lm(formula = compliance_score ~ delay_freq_num + delay_duration_num, 
##     data = data1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.2062 -0.4907  0.2004  0.6070  1.9711 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         2.81813    0.30184   9.336 3.07e-15 ***
## delay_freq_num      0.06424    0.10066   0.638    0.525    
## delay_duration_num  0.04883    0.07919   0.617    0.539    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8605 on 99 degrees of freedom
##   (48 observations deleted due to missingness)
## Multiple R-squared:  0.008509,   Adjusted R-squared:  -0.01152 
## F-statistic: 0.4248 on 2 and 99 DF,  p-value: 0.6551
summary(model_morale)
## 
## Call:
## lm(formula = morale_score ~ delay_freq_num + delay_duration_num, 
##     data = data1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.41719 -0.42080  0.08464  0.51966  1.58281 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         2.898024   0.240319  12.059   <2e-16 ***
## delay_freq_num     -0.004531   0.080145  -0.057    0.955    
## delay_duration_num  0.008189   0.063048   0.130    0.897    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6851 on 99 degrees of freedom
##   (48 observations deleted due to missingness)
## Multiple R-squared:  0.0001928,  Adjusted R-squared:  -0.02001 
## F-statistic: 0.009548 on 2 and 99 DF,  p-value: 0.9905
summary(model_product)
## 
## Call:
## lm(formula = productivity_score ~ delay_freq_num + delay_duration_num, 
##     data = data1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.6311 -0.5909 -0.1064  0.6391  2.0987 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         2.99497    0.30676   9.763 3.59e-16 ***
## delay_freq_num     -0.15881    0.10230  -1.552    0.124    
## delay_duration_num  0.09568    0.08048   1.189    0.237    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8745 on 99 degrees of freedom
##   (48 observations deleted due to missingness)
## Multiple R-squared:  0.03483,    Adjusted R-squared:  0.01533 
## F-statistic: 1.786 on 2 and 99 DF,  p-value: 0.1729
# 9. Visualization Example
ggplot(data1, aes(x = factor(delay_freq_num), y = morale_score)) +
  geom_boxplot() +
  labs(x = "Delay Frequency (0=Never, 3=More than 3 times)",
       y = "Morale Score",
       title = "Morale vs. Delay Frequency")

model_interaction <- lm(productivity_score ~ delay_freq_num * delay_duration_num, data = data1)
summary(model_interaction)
## 
## Call:
## lm(formula = productivity_score ~ delay_freq_num * delay_duration_num, 
##     data = data1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.6238 -0.6013 -0.1011  0.6417  2.0965 
## 
## Coefficients:
##                                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                        3.219320   0.662890   4.856 4.53e-06 ***
## delay_freq_num                    -0.256883   0.276395  -0.929    0.355    
## delay_duration_num                 0.008588   0.241767   0.036    0.972    
## delay_freq_num:delay_duration_num  0.037638   0.098467   0.382    0.703    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8783 on 98 degrees of freedom
##   (48 observations deleted due to missingness)
## Multiple R-squared:  0.03627,    Adjusted R-squared:  0.006764 
## F-statistic: 1.229 on 3 and 98 DF,  p-value: 0.3032