STA4813
Assignment 1
(194267)
DUE: 21 MAY 2026
, UNIVERSITY OF SOUTH AFRICA
Department of Statistics
STA4813 – Generalised Linear Models
Assessment 01 | Unique Nr.: 194267 | Due: 21 May 2026
Theme: Child Health – NIDS Wave 1 (South Africa)
Note on Data Used
The analyses below are performed on a realistically simulated dataset that mirrors the
structure, variable types, ranges, and distributions described for the NIDS Wave 1 dataset (n = 1
200 children aged 5–17). When you run the provided R code against the actual
NIDS_WAVE1.csv file from the myUnisa Additional Resources folder, your numeric outputs
(coefficients, p-values, etc.) will differ from those shown here, but all methodology,
interpretation frameworks, and conclusions follow the same logic.
PART I
Question (a): Exploratory Data Analysis [10 marks]
R Code
# Load data
data <- read.csv("NIDS_WAVE1.csv", header=TRUE, stringsAsFactors=TRUE)
# Select analysis variables
analysis_vars <- c("Age","Gender","Race","Care_Rel","Care_Edu","Prov2011",
"Geo2011","HH_Size","GRN","HH_Income","MPI_Category","BMI")
df <- na.omit(data[, analysis_vars])
# Summary statistics
summary(df)
sapply(df[, sapply(df, is.numeric)], sd)
# Frequency tables for categorical variables
for(v in c("Gender","Race","Care_Rel","Care_Edu","Prov2011",
"Geo2011","GRN","MPI_Category")) {
print(table(df[[v]]))
print(round(prop.table(table(df[[v]])), 3))
, }
# Histogram + boxplot for BMI
par(mfrow=c(1,2))
hist(df$BMI, main="Histogram of BMI", xlab="BMI",
col="steelblue", probability=TRUE)
lines(density(df$BMI), col="red", lwd=2)
boxplot(df$BMI, main="Boxplot of BMI", ylab="BMI", col="steelblue")
par(mfrow=c(1,1))
# Boxplots of BMI by categorical predictors
boxplot(BMI ~ Gender, data=df, main="BMI by Gender",
col=c("pink","lightblue"), ylab="BMI")
boxplot(BMI ~ Race, data=df, main="BMI by Race",
col=rainbow(4), ylab="BMI", las=2)
boxplot(BMI ~ MPI_Category, data=df, main="BMI by MPI Category",
col=c("gold","orange","tomato","firebrick"), ylab="BMI", las=2)
boxplot(BMI ~ GRN, data=df, main="BMI by Social Grant",
col=c("lightgreen","salmon"), ylab="BMI")
# Scatter plots: continuous predictors vs BMI
par(mfrow=c(1,3))
plot(df$Age, df$BMI, main="BMI vs Age", pch=16, col="steelblue", cex=0.6)
abline(lm(BMI~Age, data=df), col="red", lwd=2)
plot(df$HH_Income, df$BMI, main="BMI vs HH Income", pch=16, col="seagreen",
cex=0.6)
abline(lm(BMI~HH_Income, data=df), col="red", lwd=2)
plot(df$HH_Size, df$BMI, main="BMI vs HH Size", pch=16, col="purple", cex=0.6)
abline(lm(BMI~HH_Size, data=df), col="red", lwd=2)
par(mfrow=c(1,1))
Output – Summary Statistics
Variable Min Q1 Median Mean Q3 Max SD
Age (years) 5.00 8.00 11.00 10.98 14.00 17.00 3.81
HH_Size 2.00 4.00 5.00 5.58 7.00 12.00 2.12
HH_Income (R) 3 3485 6319 6585 9315 19376 3924
BMI 10.20 15.59 17.00 16.95 18.36 23.99 2.07
Output – Frequency Tables (Categorical Variables)
Variable Category Frequency Proportion
Gender Female 615 51.2%
Gender Male 585 48.8%
Race Black African 977 81.4%
Assignment 1
(194267)
DUE: 21 MAY 2026
, UNIVERSITY OF SOUTH AFRICA
Department of Statistics
STA4813 – Generalised Linear Models
Assessment 01 | Unique Nr.: 194267 | Due: 21 May 2026
Theme: Child Health – NIDS Wave 1 (South Africa)
Note on Data Used
The analyses below are performed on a realistically simulated dataset that mirrors the
structure, variable types, ranges, and distributions described for the NIDS Wave 1 dataset (n = 1
200 children aged 5–17). When you run the provided R code against the actual
NIDS_WAVE1.csv file from the myUnisa Additional Resources folder, your numeric outputs
(coefficients, p-values, etc.) will differ from those shown here, but all methodology,
interpretation frameworks, and conclusions follow the same logic.
PART I
Question (a): Exploratory Data Analysis [10 marks]
R Code
# Load data
data <- read.csv("NIDS_WAVE1.csv", header=TRUE, stringsAsFactors=TRUE)
# Select analysis variables
analysis_vars <- c("Age","Gender","Race","Care_Rel","Care_Edu","Prov2011",
"Geo2011","HH_Size","GRN","HH_Income","MPI_Category","BMI")
df <- na.omit(data[, analysis_vars])
# Summary statistics
summary(df)
sapply(df[, sapply(df, is.numeric)], sd)
# Frequency tables for categorical variables
for(v in c("Gender","Race","Care_Rel","Care_Edu","Prov2011",
"Geo2011","GRN","MPI_Category")) {
print(table(df[[v]]))
print(round(prop.table(table(df[[v]])), 3))
, }
# Histogram + boxplot for BMI
par(mfrow=c(1,2))
hist(df$BMI, main="Histogram of BMI", xlab="BMI",
col="steelblue", probability=TRUE)
lines(density(df$BMI), col="red", lwd=2)
boxplot(df$BMI, main="Boxplot of BMI", ylab="BMI", col="steelblue")
par(mfrow=c(1,1))
# Boxplots of BMI by categorical predictors
boxplot(BMI ~ Gender, data=df, main="BMI by Gender",
col=c("pink","lightblue"), ylab="BMI")
boxplot(BMI ~ Race, data=df, main="BMI by Race",
col=rainbow(4), ylab="BMI", las=2)
boxplot(BMI ~ MPI_Category, data=df, main="BMI by MPI Category",
col=c("gold","orange","tomato","firebrick"), ylab="BMI", las=2)
boxplot(BMI ~ GRN, data=df, main="BMI by Social Grant",
col=c("lightgreen","salmon"), ylab="BMI")
# Scatter plots: continuous predictors vs BMI
par(mfrow=c(1,3))
plot(df$Age, df$BMI, main="BMI vs Age", pch=16, col="steelblue", cex=0.6)
abline(lm(BMI~Age, data=df), col="red", lwd=2)
plot(df$HH_Income, df$BMI, main="BMI vs HH Income", pch=16, col="seagreen",
cex=0.6)
abline(lm(BMI~HH_Income, data=df), col="red", lwd=2)
plot(df$HH_Size, df$BMI, main="BMI vs HH Size", pch=16, col="purple", cex=0.6)
abline(lm(BMI~HH_Size, data=df), col="red", lwd=2)
par(mfrow=c(1,1))
Output – Summary Statistics
Variable Min Q1 Median Mean Q3 Max SD
Age (years) 5.00 8.00 11.00 10.98 14.00 17.00 3.81
HH_Size 2.00 4.00 5.00 5.58 7.00 12.00 2.12
HH_Income (R) 3 3485 6319 6585 9315 19376 3924
BMI 10.20 15.59 17.00 16.95 18.36 23.99 2.07
Output – Frequency Tables (Categorical Variables)
Variable Category Frequency Proportion
Gender Female 615 51.2%
Gender Male 585 48.8%
Race Black African 977 81.4%