Solutions: Exercises 1–2

Exercise 1

library(tidyverse)

sales_k_eur <- 125
employees_count <- 40
course_name <- "Research & Evidence: Data, Methods & Design"

sales_per_employee <- sales_k_eur / employees_count
sales_per_employee
[1] 3.125
employees <- read_csv(
  "data/employee_survey.csv",
  show_col_types = FALSE
)

head(employees)
# A tibble: 6 × 26
  employee_id   age gender department remote_days tenure_years manager
  <chr>       <dbl> <chr>  <chr>            <dbl>        <dbl> <chr>  
1 E000001        37 Man    Operations           3          9.2 No     
2 E000002        32 Man    Operations           3          7   No     
3 E000003        22 Man    Operations           1          0.7 No     
4 E000004        44 Woman  Technology           1          4.2 No     
5 E000005        42 Woman  Operations           3          7.4 No     
6 E000006        41 Woman  Technology           0          1.6 Yes    
# ℹ 19 more variables: training_group <chr>, leadership_1 <dbl>,
#   leadership_2 <dbl>, leadership_3 <dbl>, leadership_4_reverse <dbl>,
#   engagement_1 <dbl>, engagement_2 <dbl>, engagement_3 <dbl>,
#   engagement_4_reverse <dbl>, role_clarity_1 <dbl>, role_clarity_2 <dbl>,
#   role_clarity_3 <dbl>, role_clarity_4 <dbl>, workload <dbl>,
#   organizational_support <dbl>, job_satisfaction <dbl>, performance <dbl>,
#   burnout <dbl>, turnover_intention <dbl>
glimpse(employees)
Rows: 480
Columns: 26
$ employee_id            <chr> "E000001", "E000002", "E000003", "E000004", "E0…
$ age                    <dbl> 37, 32, 22, 44, 42, 41, 48, 23, 32, 25, 51, 39,…
$ gender                 <chr> "Man", "Man", "Man", "Woman", "Woman", "Woman",…
$ department             <chr> "Operations", "Operations", "Operations", "Tech…
$ remote_days            <dbl> 3, 3, 1, 1, 3, 0, 3, 0, 3, 4, 2, 0, 4, 1, 2, 2,…
$ tenure_years           <dbl> 9.2, 7.0, 0.7, 4.2, 7.4, 1.6, 1.6, 2.9, 10.0, 6…
$ manager                <chr> "No", "No", "No", "No", "No", "Yes", "No", "Yes…
$ training_group         <chr> "Training", "Training", "Control", "Training", …
$ leadership_1           <dbl> 1, 3, 5, 3, 3, 2, 3, 3, 5, 2, 4, 5, 1, 2, 1, 2,…
$ leadership_2           <dbl> 1, 1, 5, 2, 4, 3, 3, 4, 5, 1, 5, 5, 1, 1, 1, 2,…
$ leadership_3           <dbl> 1, 1, 5, 3, 5, 4, 4, 2, 5, 2, 5, 5, 1, 1, 2, 2,…
$ leadership_4_reverse   <dbl> 5, 5, 1, 4, 1, 3, 3, 4, 1, 5, 2, 1, 3, 4, 4, 3,…
$ engagement_1           <dbl> 2, 3, 5, 4, 5, 3, 5, 2, 5, 3, 4, 5, 3, 2, 4, 5,…
$ engagement_2           <dbl> 2, 1, 3, 5, 4, 4, 5, 1, 5, 2, 4, 5, 4, 2, 3, 1,…
$ engagement_3           <dbl> 1, 1, 4, 4, 4, 4, 5, 2, 5, 2, 5, 5, 4, 1, 3, 3,…
$ engagement_4_reverse   <dbl> 3, 4, 1, 2, 2, 4, 1, 3, 1, 5, 1, 1, 3, 5, 2, 2,…
$ role_clarity_1         <dbl> 1, 1, 4, 4, 5, 4, 3, 2, 3, 3, 5, 3, 2, 1, 1, 2,…
$ role_clarity_2         <dbl> 1, 3, 3, 5, 4, 4, 5, 3, 4, 2, 5, 5, 1, 1, 1, 1,…
$ role_clarity_3         <dbl> 1, 2, 3, 4, 4, 3, 4, 3, 5, 4, 5, 2, 2, 1, 1, 2,…
$ role_clarity_4         <dbl> 1, 4, 3, 3, 3, 2, 5, 5, 5, 3, 4, 4, 2, 1, 1, 3,…
$ workload               <dbl> 3.44, 4.68, 4.68, 4.09, 4.26, 2.25, 2.79, 4.16,…
$ organizational_support <dbl> 2.50, 3.92, 5.09, 3.72, 3.63, 3.97, 5.58, 4.25,…
$ job_satisfaction       <dbl> 2.52, 4.17, NA, 4.87, 3.17, 5.68, 4.86, 3.77, 5…
$ performance            <dbl> 45.1, 43.8, 52.2, 60.3, 59.9, NA, 64.3, 48.1, 6…
$ burnout                <dbl> 49.8, 48.5, 47.4, 47.1, 51.8, 36.3, 32.1, 46.6,…
$ turnover_intention     <dbl> 4.84, 4.18, 3.66, 4.12, 4.62, 2.83, 3.16, 5.26,…
names(employees)
 [1] "employee_id"            "age"                    "gender"                
 [4] "department"             "remote_days"            "tenure_years"          
 [7] "manager"                "training_group"         "leadership_1"          
[10] "leadership_2"           "leadership_3"           "leadership_4_reverse"  
[13] "engagement_1"           "engagement_2"           "engagement_3"          
[16] "engagement_4_reverse"   "role_clarity_1"         "role_clarity_2"        
[19] "role_clarity_3"         "role_clarity_4"         "workload"              
[22] "organizational_support" "job_satisfaction"       "performance"           
[25] "burnout"                "turnover_intention"    
dim(employees)
[1] 480  26

R is the language/statistical environment. RStudio is the IDE used to work with R.

Exercise 2

employees |>
  count(department, sort = TRUE)
# A tibble: 5 × 2
  department     n
  <chr>      <int>
1 Operations   125
2 Technology   104
3 Marketing    100
4 Finance       97
5 HR            54
employees |>
  summarise(
    mean = mean(performance, na.rm = TRUE),
    median = median(performance, na.rm = TRUE),
    sd = sd(performance, na.rm = TRUE),
    min = min(performance, na.rm = TRUE),
    max = max(performance, na.rm = TRUE)
  )
# A tibble: 1 × 5
   mean median    sd   min   max
  <dbl>  <dbl> <dbl> <dbl> <dbl>
1  53.9   54.2  9.17    25  82.4
employees |>
  summarise(
    missing_performance = sum(is.na(performance)),
    missing_satisfaction = sum(is.na(job_satisfaction))
  )
# A tibble: 1 × 2
  missing_performance missing_satisfaction
                <int>                <int>
1                   8                    8
employees |>
  group_by(department) |>
  summarise(
    n = n(),
    mean_performance = mean(performance, na.rm = TRUE),
    .groups = "drop"
  )
# A tibble: 5 × 3
  department     n mean_performance
  <chr>      <int>            <dbl>
1 Finance       97             53.6
2 HR            54             51.7
3 Marketing    100             55.2
4 Operations   125             52.7
5 Technology   104             55.7
ggplot(employees, aes(x = performance)) +
  geom_histogram(binwidth = 5, boundary = 0)

ggplot(employees, aes(x = training_group, y = performance)) +
  geom_boxplot()

employees_optional <- employees |>
  mutate(
    work_mode = case_when(
      remote_days == 0 ~ "On-site",
      remote_days <= 3 ~ "Hybrid",
      TRUE ~ "Mostly remote"
    )
  )

A descriptive difference can be reported as a sample pattern. It should not be described as a causal effect unless the design justifies that claim.