gravatar

zayanma

Zaya

Recently Published

Comparison of AI Capability, Public Sector Innovation, and Government Strategy by Decision Class
library(ggplot2) ggplot(merged_data, aes(x = Decision_Class, y = AI_Capability_Index, fill = Decision_Class)) + geom_boxplot() + theme_minimal() + labs(title = "AI Capability Index by Decision Class", x = "Decision Class", y = "AI Capability Index") # Visualize Public Sector Innovation across decision classes merged_data_long <- pivot_longer(merged_data, cols = c(AI_Capability_Index, Public_Sector_Innovation, Government.Strategy), names_to = "Metric", values_to = "Value") # Combined boxplot comparing AI Capability Index, Public Sector Innovation, and Government.Strategy ggplot(merged_data_long, aes(x = Decision_Class, y = Value, fill = Metric)) + geom_boxplot(position = position_dodge(0.8)) + theme_minimal() + labs(title = "Comparison of AI Capability, Public Sector Innovation, and Government Strategy by Decision Class", x = "Decision Class", y = "Development Factor", fill = "Metric") + theme(legend.title = element_text(face = "bold"), plot.title = element_text(hjust = 0.5))
Map Visualization (Developed vs Developing Countries on a World Map)
install.packages("rworldmap") library(rworldmap) # Merge the classification data with a world map map_data <- joinCountryData2Map(merged_data, joinCode = "NAME", nameJoinColumn = "Country") # Visualize the classification on a world map mapCountryData(map_data, nameColumnToPlot = "Economic_Development", mapTitle = "Developed vs Developing Countries", catMethod = "categorical", colourPalette = c("Developed" = "#2E86C1", "Developing" = "#F39C12"))
AI Capability Index
plot(merged_data$norm_talent, merged_data$AI_Capability_Index, xlab = "Normalized Talent", ylab = "AI Capability Index")
Normalized Talent by Country
boxplot(norm_talent ~ Country, data = merged_data, main = "Normalized Talent by Country", xlab = "Country", ylab = "Normalized Talent")
Plot
PlotDistribution of Decision Variable
summary(merged_data$Decision) hist(merged_data$Decision, main = "Distribution of Decision Variable", xlab = "Decision Score")
Innovation Leaders vs. Followers
library(lime) explainer <- lime(train_data_2, logistic_model) explanation <- explain(test_data_2[sample(1:nrow(test_data_2), 10), ], explainer, n_labels = 1, n_features = 2) plot_features(explanation)
Visualize the LIME explanations
library(lime) explainer <- lime(train_data_1[, c("AI_Capability_Index", "Public_Sector_Innovation")], model_politic) # Explain a few instances from the test set explanation <- explain(test_data_1[1:5, c("AI_Capability_Index", "Public_Sector_Innovation")], explainer, n_labels = 1, n_features = 3) # Visualize the LIME explanations plot_features(explanation)
classficication
###classficication # Load necessary libraries library(randomForest) library(caret) # Define the predictors and target variable predictors <- merged_data[, c("Talent", "Infrastructure", "Operating.Environment", "Research", "Development", "Government.Strategy", "AI_Capability_Index", "Public_Sector_Innovation")] target <- merged_data$Political.regime # Train-test split set.seed(123) trainIndex <- createDataPartition(target, p = .8, list = FALSE, times = 1) trainData <- merged_data[trainIndex, ] testData <- merged_data[-trainIndex, ] # Fit a random forest model rf_model <- randomForest(as.factor(Political.regime) ~ Talent + Infrastructure + Operating.Environment + Research + Development + Government.Strategy + AI_Capability_Index + Public_Sector_Innovation, data = trainData, ntree = 500, mtry = 3, importance = TRUE) # Model Evaluation predictions <- predict(rf_model, testData) confusionMatrix(predictions, testData$Political.regime) # View feature importance importance(rf_model) varImpPlot(rf_model)
AI Capability Index Distribution
# Histograms for AI_Capability_Index and Public_Sector_Innovation hist(merged_data$AI_Capability_Index, main = "AI Capability Index Distribution", xlab = "AI Capability Index", col = "lightblue")
Public Sector Innovation Distribution
hist(merged_data$Public_Sector_Innovation, main = "Public Sector Innovation Distribution", xlab = "Public Sector Innovation", col = "lightgreen")
Countries Ranked by AI Capability and Geopolitical Decision Influence
ggplot(merged_data, aes(x = reorder(Country, -AI_Capability_Index), y = AI_Capability_Index, fill = as.factor(Decision))) + geom_bar(stat = "identity") + coord_flip() + # Flip for horizontal bars labs(title = "Countries Ranked by AI Capability and Geopolitical Decision Influence", x = "Country", y = "AI Capability Index", fill = "Decision Impact") + theme_minimal()
Clustered Heatmap of AI Capability and Geopolitical Factors
> data_to_cluster <- merged_data[, c("AI_Capability_Index", "Talent", "Public_Sector_Innovation")] > > data_scaled <- scale(data_to_cluster) > pheatmap(data_scaled, + cluster_rows = TRUE, cluster_cols = TRUE, + main = "Clustered Heatmap of AI Capability and Geopolitical Factors", + display_numbers = TRUE)
Rpart.Plot
decision_tree <- rpart(Political.regime ~ Talent + Infrastructure + AI_Capability_Index + Public_Sector_Innovation, data = df, method = "class") # Plot the decision tree rpart.plot(decision_tree, type = 2, extra = 104, under = TRUE, faclen = 0, cex = 0.8)
custom annotations to describe the clusters
# Add custom annotations to describe the clusters ggplot(hclust.project2D, aes(x = PC1, y = PC2)) + geom_point(aes(shape = cluster_label, color = cluster_label), size = 3) + geom_text(aes(label = country, color = cluster_label), hjust = 0, vjust = 1, size = 3) + geom_polygon(data = hclust.hull, aes(group = cluster, fill = as.factor(cluster)), alpha = 0.4, linetype = 0) + theme_minimal() + labs(title = "Geopolitical Decisions Based on AI Capabilities", x = "Principal Component 1 (AI Capability)", y = "Principal Component 2 (Government Strategy)", color = "Cluster", shape = "Cluster") + scale_fill_manual(values = c("#FF9999", "#99CCFF", "#66CC66"), labels = c("AI Leaders", "Emerging AI Players", "Tech Adopters")) + theme(text = element_text(size = 16)) + annotate("text", x = 5, y = -2, label = "AI Leaders: Advanced AI capabilities, \nForm AI alliances, Lead AI standards", color = "#FF9999", size = 5, hjust = 0) + annotate("text", x = -4, y = 3, label = "Emerging AI Players: Focus on AI regulation, \nBuild partnerships for growth", color = "#99CCFF", size = 5, hjust = 0) + annotate("text", x = -6, y = -5, label = "Tech Adopters: Focus on cybersecurity, \nEnsure digital sovereignty", color = "#66CC66", size = 5, hjust = 0)
clusters with meaningful labels
library(ggplot2) # Plot the clusters with meaningful labels ggplot(hclust.project2D, aes(x = PC1, y = PC2)) + geom_point(aes(shape = cluster_label, color = cluster_label), size = 3) + geom_text(aes(label = country, color = cluster_label), hjust = 0, vjust = 1, size = 3) + geom_polygon(data = hclust.hull, aes(group = cluster, fill = as.factor(cluster)), alpha = 0.4, linetype = 0) + theme_minimal() + labs(title = "Geopolitical Decisions Based on AI Capabilities", x = "Principal Component 1 (AI Capability)", y = "Principal Component 2 (Government Strategy)", color = "Cluster", shape = "Cluster") + scale_fill_manual(values = c("#FF9999", "#99CCFF", "#66CC66"), labels = c("AI Leaders", "Emerging AI Players", "Tech Adopters")) + theme(text = element_text(size = 16))
Project2d
# data prepare for clustering visualization princ <- prcomp(scaled_data) nComp <- 2 project2D <- as.data.frame(predict(princ, newdata=scaled_data)[,1:nComp]) hclust.project2D <- cbind(project2D, cluster=as.factor(groups), country=df$Country) head(hclust.project2D) library('grDevices') find_convex_hull <-function(proj2Ddf,groups) { do.call(rbind, lapply(unique(groups), FUN= function(c){ f<-subset(proj2Ddf,cluster==c); f[chull(f),] } ) ) } hclust.hull <-find_convex_hull(hclust.project2D,groups) library(ggplot2) ggplot(hclust.project2D, aes(x=PC1,y=PC2)) + geom_point(aes(shape=cluster,color=cluster)) + geom_text(aes(label=country,color=cluster),hjust=0,vjust=1, size=3) + geom_polygon(data=hclust.hull, aes(group=cluster,fill=as.factor(cluster)), alpha=0.4, linetype=0) + theme(text=element_text(size=20))
BoxPlot
# Add cluster information to the dataset df$Cluster <- groups # Plot the boxplot ggplot(df, aes(x = as.factor(Cluster), y = AI_Capability_Index, fill = as.factor(Cluster))) + geom_boxplot() + labs(title = "Distribution of AI Capability Index by Cluster", x = "Cluster", y = "AI Capability Index") + theme_minimal()
BarPlot
# Calculate the mean AI_Capability_Index for each cluster and region library(dplyr) cluster_summary <- df %>% mutate(cluster = groups) %>% group_by(cluster, Region) %>% summarise(mean_AICapability = mean(AI_Capability_Index, na.rm = TRUE)) # Plot the bar plot library(ggplot2) ggplot(cluster_summary, aes(x = Region, y = mean_AICapability, fill = as.factor(cluster))) + geom_bar(stat = "identity", position = "dodge") + labs(title = "AI Capability Index by Region and Cluster", x = "Region", y = "Mean AI Capability Index", fill = "Cluster") + theme_minimal()
Dendrogram
Dendrogram is a tree-like diagram that shows the hierarchical structure of the clusters library(dynamicTreeCut) dist_matrix <- dist(merged_data[, -1]) # Assuming the first column is 'Region' hclust_model <- hclust(dist_matrix, method = "ward.D2") options(repr.plot.width = 16, repr.plot.height = 10) plot(hclust_model, labels = merged_data$Region, main = "Hierarchical Clustering Dendrogram", xlab = "Region", ylab = "Height", sub = "", cex = 0.4, las = 2) rect.hclust(hclust_model, k = 5, border = "red") dendro_colors <- cutreeDynamic(hclust_model, distM = as.matrix(dist_matrix), method = "tree") plot(hclust_model, labels = merged_data$Region, main = "Hierarchical Clustering Dendrogram with Dynamic Cut", xlab = "Region", ylab = "Height", sub = "", cex = 0.4, las = 2) rect.hclust(hclust_model, k = 5, border = "red")
rpart
> library(rpart) > library(rpart.plot) > > # Train decision tree model > decision_tree <- rpart(Decision ~ AI_Capability_Index + Public_Sector_Innovation + Talent + Infrastructure + Government.Strategy, + data = merged_data, method = "class") > > # Plot the decision tree > rpart.plot(decision_tree, type = 3, extra = 104, fallen.leaves = TRUE, main = "Geopolitical Decisions")
BoxPlot
ggplot(merged_data, aes(x = Political.regime, y = AI_Capability_Index)) + geom_boxplot() + theme_minimal() Compare the distribution of AI_Capability_Index across different Political.regime categories.
AI cap and Infra
library(ggplot2) ggplot(merged_data, aes(x = Infrastructure, y = AI_Capability_Index)) + geom_point() + geom_smooth(method = "lm") + theme_minimal()
AI capability vs Total.score
AI capability vs Total.score have strong relationships ggplot(merged_data, aes(x = `Total score`, y = AI_Capability_Index)) + geom_point(color = "blue", alpha = 0.7) + geom_smooth(method = "lm", color = "red", se = FALSE) + labs(title = "Relationship Between AI Capability Index and Total Score", x = "Total Score", y = "AI Capability Index") + theme_minimal()
AI Capability by Income Group
see how the AI capability index varies across different income groups
1. AI capability across the world
analyze how AI capability varies by region or country cluster
corr_3_matrix
plot shows correlations between Government AI Strategy, AI capability index, and Political Regime (numerically encoded). This will help identify linear relationships between these factors
HTML
plot shows the Government AI Strategy, AI Readiness, and Political Regime in a 3D space, allowing you to see how these factors interact. You can rotate and explore different angles of the 3D scatter plot
HeatMap-Three-Factors
show the mean AI readiness for each combination of Political Regime and Government AI Strategy. You can spot which combinations are most effective at driving AI readiness.
Pair Plot
This visualization will show pairwise scatter plots for each combination of the variables: Government Strategy vs AI Readiness. Government Strategy vs Political Regime. AI Readiness vs Political Regime. The plot will help you identify relationships, trends, and interactions between the three variables. The color coding by Political Regime helps distinguish different regimes visually
FacetGrid
visualization helps you understand the interaction between Government AI Strategy and Political Regime, showing how different regimes approach AI strategy and how it impacts AI readiness
Plot
plot shows the full distribution of AI readiness for each political regime, highlighting areas of high density, median values, and variability.
HeatMap-Correlations
heatmap shows the strength of the correlations between political regimes, AI readiness, government AI strategy, and income group. This helps to identify patterns (e.g., whether certain regimes are highly correlated with high AI readiness) ggplot(melted_corr, aes(Var1, Var2, fill = value)) + geom_tile() + scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0) + labs(title = "Correlation Heatmap of AI Readiness and Political Regime") + theme_minimal()
BoxPlot - AI capabilities
plot will show the distribution of AI readiness for each political regime, helping to compare how AI readiness differs between regimes (e.g., do liberal democracies have higher AI readiness than closed autocracies?)
Plot
ai-forecast
innovation-impact
Plot-ai-readiness
tree_model
Decision trees classify data by creating a tree-like model of decisions. The rpart package can be used to create a decision tree.
K-means
K-means algorithm follows an iterative process to assign data points to K clusters, where K is the number of clusters specified by the user
Plot the regression line to visualize the relationship
Linear Regression (e.g., Impact of Government Strategy on AI Metrics) Linear regression helps quantify the relationship between geopolitical factors (e.g., government strategy) and AI metrics (e.g., infrastructure, research).
Visualizing Trends with Facets and Grouping
You can also visualize trends across different categories using faceting and grouping in ggplot2.
ggplot2
Interactive Visualization with ggplot2 Use ggplot2 for more flexible and polished visualizations.
Visualize Trends overtime
If your data contains time information (e.g., years of projects in the public sector data), you can visualize trends over time.
Pairwise Scatter Plot (Pair Plot)
For numeric variables, a pair plot helps you visualize relationships between all variables simultaneously. pairs(~ Talent + Infrastructure + Development + `Total score`, data=merged_data, main="Pairwise Scatter Plot")
correlation matrix
# Visualize the correlation matrix library(corrplot) corrplot(cor_matrix, method="color", type="upper", tl.col="black", tl.srt=45)
mosaicplot
mosaicplot(table(ai_data$Political.regime, ai_data$Region), main="Region vs Political Regime", col=c("skyblue", "pink", "yellow"))
Plot
plot(merged_data$Development, merged_data$AI_Index_Score, main="AI Index score vs Development", xlab="Development", ylab="Total Score", pch=19, col="blue")
Plot
Distribution of Income Groups
Plot
Plot
Plot
Plot
Plot
Plot
Plot
Plot
Project-1