0% found this document useful (0 votes)
4 views11 pages

People Analytics InSEM

The document outlines a data analysis process using R for employee engagement scores, including data cleaning, descriptive statistics, and visualization. It performs a two-sample t-test to compare engagement scores between Sales and Marketing departments, checking for normality and equal variance. The conclusion is drawn based on the p-value from the t-test to determine if there is a statistically significant difference in engagement scores.

Uploaded by

tanvir.anam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views11 pages

People Analytics InSEM

The document outlines a data analysis process using R for employee engagement scores, including data cleaning, descriptive statistics, and visualization. It performs a two-sample t-test to compare engagement scores between Sales and Marketing departments, checking for normality and equal variance. The conclusion is drawn based on the p-value from the t-test to determine if there is a statistically significant difference in engagement scores.

Uploaded by

tanvir.anam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

CamScanner

CamScanner
CamScanner
Question 02 Code

# Load required libraries

install.packages("tidyverse", dependencies = TRUE) # If not installed

install.packages("ggpubr") # For visualization

tinstall.packages("dplyr") # Data manipulation

library(tidyverse)

library(ggpubr)

library(dplyr)

# Set working directory (update path accordingly)

setwd("D:/R")

# Load the dataset

engagement_data <- read.csv("employee_engagement.csv")

# View first few rows

head(engagement_data)

# ---------------- STEP 1: Data Cleaning ----------------

# Check for missing values

sum(is.na(engagement_data))

# Remove rows with missing values if any

engagement_data <- na.omit(engagement_data)


# ---------------- STEP 2: Descriptive Statistics ----------------

# Summary statistics by department

stats_by_department <- engagement_data %>%

group_by(Department) %>%

summarise(

Mean = mean(Engagement_Score, na.rm = TRUE),

Median = median(Engagement_Score, na.rm = TRUE),

Std_Dev = sd(Engagement_Score, na.rm = TRUE)

# Print descriptive statistics

print(stats_by_department)

# ---------------- STEP 3: Visualization ----------------

# Boxplot of Engagement Scores by Department

ggplot(engagement_data, aes(x = Department, y = Engagement_Score, fill = Department)) +

geom_boxplot() +

labs(title = "Employee Engagement Scores by Department", x = "Department", y =


"Engagement Score") +

theme_minimal()

# ---------------- STEP 4: Two-Sample T-Test ----------------


# Check for normality assumption using Shapiro-Wilk test

shapiro.test(engagement_data$Engagement_Score[engagement_data$Department ==
"Sales"])

shapiro.test(engagement_data$Engagement_Score[engagement_data$Department ==
"Marketing"])

# Check for equal variance using Levene’s test

install.packages("car")

library(car)

leveneTest(Engagement_Score ~ Department, data = engagement_data)

# Conduct Two-Sample T-Test

t_test_results <- t.test(Engagement_Score ~ Department, data = engagement_data,


var.equal = FALSE)

# Print T-Test results

print(t_test_results)

# ---------------- STEP 5: Interpretation ----------------

# Extract p-value and confidence intervals

p_value <- t_test_results$p.value

conf_int <- t_test_results$conf.int

cat("P-Value:", p_value, "\n")

cat("Confidence Interval:", conf_int[1], "to", conf_int[2], "\n")


# Conclusion based on p-value

if (p_value < 0.05) {

cat("There is a statistically significant difference in engagement scores between Sales and


Marketing.\n")

} else {

cat("There is no statistically significant difference in engagement scores between Sales


and Marketing.\n")

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy