Upload folder using huggingface_hub
Browse files- examples/basic_analysis.R +100 -0
- examples/basic_analysis.py +82 -0
examples/basic_analysis.R
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Australian Health and Geographic Data (AHGD) - R Example
|
2 |
+
#
|
3 |
+
# This example demonstrates how to load and analyse the AHGD dataset using R
|
4 |
+
|
5 |
+
library(arrow) # For Parquet files
|
6 |
+
library(readr) # For CSV files
|
7 |
+
library(jsonlite) # For JSON files
|
8 |
+
library(dplyr) # For data manipulation
|
9 |
+
library(ggplot2) # For visualisation
|
10 |
+
|
11 |
+
# Load dataset (Parquet recommended for performance)
|
12 |
+
load_ahgd_data <- function(format = "parquet") {
|
13 |
+
if (format == "parquet") {
|
14 |
+
data <- arrow::read_parquet("ahgd_data.parquet")
|
15 |
+
} else if (format == "csv") {
|
16 |
+
data <- readr::read_csv("ahgd_data.csv")
|
17 |
+
} else if (format == "json") {
|
18 |
+
json_data <- jsonlite::fromJSON("ahgd_data.json")
|
19 |
+
data <- as.data.frame(json_data$data)
|
20 |
+
} else {
|
21 |
+
stop("Unsupported format. Use 'parquet', 'csv', or 'json'")
|
22 |
+
}
|
23 |
+
|
24 |
+
return(data)
|
25 |
+
}
|
26 |
+
|
27 |
+
# Basic analysis
|
28 |
+
analyse_ahgd <- function() {
|
29 |
+
# Load data
|
30 |
+
df <- load_ahgd_data("parquet")
|
31 |
+
|
32 |
+
cat("Dataset dimensions:", dim(df), "\n")
|
33 |
+
cat("Column names:", paste(names(df), collapse = ", "), "\n\n")
|
34 |
+
|
35 |
+
# Summary statistics for numeric columns
|
36 |
+
numeric_cols <- sapply(df, is.numeric)
|
37 |
+
if (any(numeric_cols)) {
|
38 |
+
cat("Summary statistics:\n")
|
39 |
+
print(summary(df[, numeric_cols]))
|
40 |
+
}
|
41 |
+
|
42 |
+
# State-level health indicators
|
43 |
+
if ("state_name" %in% names(df) && "life_expectancy_years" %in% names(df)) {
|
44 |
+
state_summary <- df %>%
|
45 |
+
group_by(state_name) %>%
|
46 |
+
summarise(
|
47 |
+
avg_life_expectancy = mean(life_expectancy_years, na.rm = TRUE),
|
48 |
+
avg_smoking = mean(smoking_prevalence_percent, na.rm = TRUE),
|
49 |
+
avg_obesity = mean(obesity_prevalence_percent, na.rm = TRUE),
|
50 |
+
.groups = 'drop'
|
51 |
+
)
|
52 |
+
|
53 |
+
cat("\nHealth indicators by state:\n")
|
54 |
+
print(state_summary)
|
55 |
+
}
|
56 |
+
|
57 |
+
return(df)
|
58 |
+
}
|
59 |
+
|
60 |
+
# Create visualisations
|
61 |
+
create_plots <- function(df) {
|
62 |
+
# Life expectancy distribution
|
63 |
+
p1 <- ggplot(df, aes(x = life_expectancy_years)) +
|
64 |
+
geom_histogram(bins = 20, fill = "skyblue", alpha = 0.7) +
|
65 |
+
labs(title = "Distribution of Life Expectancy",
|
66 |
+
x = "Life Expectancy (Years)",
|
67 |
+
y = "Count") +
|
68 |
+
theme_minimal()
|
69 |
+
|
70 |
+
# Smoking vs Life Expectancy
|
71 |
+
if (all(c("smoking_prevalence_percent", "life_expectancy_years") %in% names(df))) {
|
72 |
+
p2 <- ggplot(df, aes(x = smoking_prevalence_percent, y = life_expectancy_years)) +
|
73 |
+
geom_point(alpha = 0.6, color = "darkblue") +
|
74 |
+
geom_smooth(method = "lm", se = TRUE, color = "red") +
|
75 |
+
labs(title = "Smoking Prevalence vs Life Expectancy",
|
76 |
+
x = "Smoking Prevalence (%)",
|
77 |
+
y = "Life Expectancy (Years)") +
|
78 |
+
theme_minimal()
|
79 |
+
|
80 |
+
# Save plots
|
81 |
+
ggsave("life_expectancy_distribution.png", p1, width = 8, height = 6, dpi = 300)
|
82 |
+
ggsave("smoking_vs_life_expectancy.png", p2, width = 8, height = 6, dpi = 300)
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
# Run analysis
|
87 |
+
main <- function() {
|
88 |
+
cat("Loading Australian Health and Geographic Data...\n")
|
89 |
+
data <- analyse_ahgd()
|
90 |
+
|
91 |
+
cat("Creating visualisations...\n")
|
92 |
+
create_plots(data)
|
93 |
+
|
94 |
+
cat("Analysis complete!\n")
|
95 |
+
}
|
96 |
+
|
97 |
+
# Execute if run directly
|
98 |
+
if (sys.nframe() == 0) {
|
99 |
+
main()
|
100 |
+
}
|
examples/basic_analysis.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Example: Basic analysis of Australian Health and Geographic Data
|
3 |
+
|
4 |
+
This example demonstrates how to load and analyse the AHGD dataset
|
5 |
+
using Python and common data science libraries.
|
6 |
+
"""
|
7 |
+
|
8 |
+
import pandas as pd
|
9 |
+
import matplotlib.pyplot as plt
|
10 |
+
import seaborn as sns
|
11 |
+
|
12 |
+
def load_dataset(format_type='parquet'):
|
13 |
+
"""Load AHGD dataset in specified format."""
|
14 |
+
if format_type == 'parquet':
|
15 |
+
return pd.read_parquet('ahgd_data.parquet')
|
16 |
+
elif format_type == 'csv':
|
17 |
+
return pd.read_csv('ahgd_data.csv')
|
18 |
+
elif format_type == 'json':
|
19 |
+
import json
|
20 |
+
with open('ahgd_data.json', 'r') as f:
|
21 |
+
data = json.load(f)
|
22 |
+
return pd.DataFrame(data['data'])
|
23 |
+
else:
|
24 |
+
raise ValueError(f"Unsupported format: {format_type}")
|
25 |
+
|
26 |
+
def basic_analysis():
|
27 |
+
"""Perform basic statistical analysis."""
|
28 |
+
# Load data
|
29 |
+
df = load_dataset('parquet')
|
30 |
+
|
31 |
+
print(f"Dataset shape: {df.shape}")
|
32 |
+
print(f"Columns: {list(df.columns)}")
|
33 |
+
|
34 |
+
# Summary statistics
|
35 |
+
numeric_cols = df.select_dtypes(include=['float64', 'int64']).columns
|
36 |
+
print("\nSummary Statistics:")
|
37 |
+
print(df[numeric_cols].describe())
|
38 |
+
|
39 |
+
# State-level aggregations
|
40 |
+
if 'state_name' in df.columns and 'life_expectancy_years' in df.columns:
|
41 |
+
state_health = df.groupby('state_name').agg({
|
42 |
+
'life_expectancy_years': 'mean',
|
43 |
+
'smoking_prevalence_percent': 'mean',
|
44 |
+
'obesity_prevalence_percent': 'mean'
|
45 |
+
}).round(2)
|
46 |
+
|
47 |
+
print("\nHealth Indicators by State:")
|
48 |
+
print(state_health)
|
49 |
+
|
50 |
+
return df
|
51 |
+
|
52 |
+
def create_visualisations(df):
|
53 |
+
"""Create basic visualisations."""
|
54 |
+
plt.style.use('seaborn-v0_8')
|
55 |
+
|
56 |
+
# Life expectancy distribution
|
57 |
+
plt.figure(figsize=(10, 6))
|
58 |
+
plt.subplot(2, 2, 1)
|
59 |
+
df['life_expectancy_years'].hist(bins=20, alpha=0.7)
|
60 |
+
plt.title('Distribution of Life Expectancy')
|
61 |
+
plt.xlabel('Years')
|
62 |
+
|
63 |
+
# Health indicators correlation
|
64 |
+
if all(col in df.columns for col in ['life_expectancy_years', 'smoking_prevalence_percent']):
|
65 |
+
plt.subplot(2, 2, 2)
|
66 |
+
plt.scatter(df['smoking_prevalence_percent'], df['life_expectancy_years'], alpha=0.6)
|
67 |
+
plt.xlabel('Smoking Prevalence (%)')
|
68 |
+
plt.ylabel('Life Expectancy (Years)')
|
69 |
+
plt.title('Smoking vs Life Expectancy')
|
70 |
+
|
71 |
+
plt.tight_layout()
|
72 |
+
plt.savefig('ahgd_analysis.png', dpi=300, bbox_inches='tight')
|
73 |
+
plt.show()
|
74 |
+
|
75 |
+
if __name__ == "__main__":
|
76 |
+
# Run basic analysis
|
77 |
+
data = basic_analysis()
|
78 |
+
|
79 |
+
# Create visualisations
|
80 |
+
create_visualisations(data)
|
81 |
+
|
82 |
+
print("\nAnalysis complete! Check ahgd_analysis.png for visualisations.")
|