simulate_student_features <- function(n = 100) {
# Set the random seed
set.seed(260923)
# Generate unique student IDs
student_ids <- seq(1, n)
# Simulate student engagement
student_engagement <- rnorm(n, mean = 50, sd = 10)
# Simulate student performance
student_performance <- rnorm(n, mean = 60, sd = 15)
# Combine the data into a data frame
student_features <- data.frame(
student_id = student_ids,
student_engagement = student_engagement,
student_performance = student_performance
)
# Return the data frame
return(student_features)
}
# Load required library
library(ggplot2)
# Generate simulated student features data
student_data <- simulate_student_features()
# Perform k-means clustering
set.seed(123) # for reproducibility
kmeans_result <- kmeans(student_data[, -1], centers = 3) # excluding student_id for clustering
# Add cluster labels to the data
student_data$cluster <- as.factor(kmeans_result$cluster)
# Visualize the clusters
ggplot2::ggplot(student_data, ggplot2::aes(x = student_engagement, y = student_performance, color = cluster)) +
ggplot2::geom_point() +
ggplot2::labs(title = "K-Means Clustering of Student Features",
x = "Student Engagement",
y = "Student Performance",
color = "Cluster") +
ggplot2::theme_minimal()

# Load required library
library(ggplot2)
# Simulate student features
simulate_student_features <- function(n = 100) {
# Set the random seed
set.seed(260923)
# Generate unique student IDs
student_ids <- seq(1, n)
# Simulate student engagement
student_engagement <- rnorm(n, mean = 50, sd = 10)
# Simulate student performance
student_performance <- rnorm(n, mean = 60, sd = 15)
# Combine the data into a data frame
student_features <- data.frame(
student_id = student_ids,
student_engagement = student_engagement,
student_performance = student_performance
)
# Return the data frame
return(student_features)
}
# Generate simulated student features data
student_data <- simulate_student_features()
# Perform PCA
pca_result <- prcomp(student_data[, -1], scale. = TRUE)
# Extract the PC scores
pc_scores <- as.data.frame(pca_result$x)
# Add cluster labels to student data
student_data$cluster <- as.factor(kmeans(pca_result$x, centers = 3)$cluster)
# Visualize PCA
ggplot(pc_scores, aes(x = PC1, y = PC2, color = student_data$cluster)) +
geom_point() +
labs(title = "PCA of Student Features",
x = "Principal Component 1",
y = "Principal Component 2",
color = "Cluster") +
theme_minimal()
