‘simulate_student_features’ it is a function that generates simulated data for student features and the features are Student IDs, engagement scores, and Performance Scores and the student engagement and performance are simulated using random normal distributions with specified ,means and standard deviations.
Kmeans() function is used to performed the student for k-means clustring and the clustrs ‘k’ is set as 3, cluster labels are added to dataset
this function simulate_student_features() is called to generate the student data and the values is stored into student_data
the centroid of the clusters are printed to the console
the PCA is performed on the student data using prcomp() function and the conducted to reduce the dimensional of the data set and visualize patterns with PCA is applied to the performance features
to see the summary of PCA result
A plot which shows both the data points and the principl components, using plot() function
Cluster Centers: student_engagement student_performance 1 52.16734 72.958674 2 43.87698 48.265178 3 65.41259 58.720237
Cluster 1: Higher Engagement, Higher Performance: This cluster may represent students who are highly engaged in their studies and demonstrate strong academic performance.
Cluster 2: Lower Engagement, Lower Performance: This cluster could consist of students who exhibit low levels of engagement and struggle academically
Cluster 3: Higher Engagement, Moderate Performance: This cluster may include students who are actively engaged in their studies but achieve moderate academic performance.
Learning Designs are ways of describing an educational experience such that it can be applied across a range of disciplinary contexts. Learning analytics offers new approaches to investigating the data associated with a learner’s experience.
AUTHERS: Shane Dawson, Lori Lockyer
# Define the function to 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 the dataset
student_data <- simulate_student_features()
# View the dataset
head(student_data)
## student_id student_engagement student_performance
## 1 1 35.47855 50.52231
## 2 2 51.79512 58.88396
## 3 3 62.41012 40.56755
## 4 4 35.20679 62.46033
## 5 5 59.37552 54.69326
## 6 6 57.00109 54.09745
## Clustering using K-means
set.seed(123) # Setting seed for reproducibility
k <- 3 # Number of clusters
student_clusters <- kmeans(student_data[, -1], centers = k)
# Add cluster labels to the dataset
student_data$cluster <- as.factor(student_clusters$cluster)
# Display cluster centers
print("Cluster Centers:")
## [1] "Cluster Centers:"
print(student_clusters$centers)
## student_engagement student_performance
## 1 55.27903 73.69308
## 2 38.88027 63.76751
## 3 53.96117 46.83341
# Dimensionality reduction using PCA
student_pca <- prcomp(student_data[, -c(1, 4)], scale. = TRUE)
# Summarize the PCA results
summary(student_pca)
## Importance of components:
## PC1 PC2
## Standard deviation 1.0104 0.9895
## Proportion of Variance 0.5104 0.4896
## Cumulative Proportion 0.5104 1.0000
# Plot the variance explained by each principal component
plot(student_pca, type = "l")
# Biplot to visualize the data and the principal components
biplot(student_pca)
# Increase the size of the plots
par(mfrow = c(1, 2), mar = c(5, 5, 2, 2)) # Adjust mfrow for the number of plots and mar for margins
# Plot the variance explained by each principal component
plot(student_pca, type = "l")
# Biplot to visualize the data and the principal components
biplot(student_pca)
library(ggplot2)
# Convert PCA results to a data frame
pca_df <- as.data.frame(student_pca$x[, 1:2])
# Add cluster labels
pca_df$cluster <- student_data$cluster
# Create a ggplot for the biplot
ggplot(pca_df, aes(x = PC1, y = PC2, color = cluster)) +
geom_point() +
geom_hline(yintercept = 0, linetype = "dashed", color = "gray50") +
geom_vline(xintercept = 0, linetype = "dashed", color = "gray50") +
labs(x = paste("PC1 (", round(summary(student_pca)$importance[2,1]*100, 2), "%)"),
y = paste("PC2 (", round(summary(student_pca)$importance[2,2]*100, 2), "%)")) +
theme_minimal() +
theme(legend.position = "right")
You can also embed plots, for example:
# Convert PCA results to a data frame
pca_df <- as.data.frame(student_pca$x[, 1:2])
# Add cluster labels
pca_df$cluster <- student_data$cluster
# Create a ggplot for the biplot
ggplot(pca_df, aes(x = PC1, y = PC2, color = cluster)) +
geom_point() +
geom_hline(yintercept = 0, linetype = "dashed", color = "gray50") +
geom_vline(xintercept = 0, linetype = "dashed", color = "gray50") +
labs(x = paste("PC1 (", round(summary(student_pca)$importance[2,1]*100, 2), "%)"),
y = paste("PC2 (", round(summary(student_pca)$importance[2,2]*100, 2), "%)")) +
theme_minimal() +
theme(legend.position = "right")
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.