Alimin Adi Waloyo

2025-12-7

Read SPSS data set “US_TIMSS_sample.SAV”.

library(haven)
timss_data <- read_sav("2_US_TIMSS_sample.SAV")

1.2 Recode variables from “BSBG06A” to “BSBG06K” by recoding Yes =1, No =0, Omitted or invalid = “Missing”, rename the new recoded variables using “BSBG06AR” … “BSBG06KR”.

for (var in paste0("BSBG06", LETTERS[1:11])) {
  new_var <- paste0(var, "R")
  timss_data[[new_var]] <- ifelse(timss_data[[var]] ==
                                        1, 1,
                                      ifelse(timss_data[[var]] == 2, 0, NA))
}

1.3 Create a new variable “Resources” by computing a total score of across variables created in 1.2 (i.e., BSBG06AR … BSBG06KR).

timss_data$Resources <- rowSums(timss_data[paste0("BSBG06", LETTERS[1:11], "R")], na.rm = TRUE)

Task 2 - Descriptive Statistics

2.1 Obtain descriptive statistics (M, SD, MIN, MAX, Skewness, Kurtosis) and histograms for the variables: MathScore, EnjoyMath, Resources, Books

(Are there any missing data?)

library(moments)
variables <- c("MathScore", "EnjoyMath", "Resources", "Books")
descriptive_stats <- data.frame(Variable = variables,
                                Mean = sapply(timss_data[variables], mean, na.rm = TRUE),
                                SD = sapply(timss_data[variables], sd, na.rm = TRUE),
                                Min = sapply(timss_data[variables], min, na.rm = TRUE),
                                Max = sapply(timss_data[variables], max, na.rm = TRUE),
                                Skewness = sapply(timss_data[variables], skewness, na.rm = TRUE),
                                Kurtosis = sapply(timss_data[variables], kurtosis, na.rm = TRUE))
print(descriptive_stats)
##            Variable       Mean        SD       Min       Max   Skewness
## MathScore MathScore 509.472203 77.211941 333.81193 691.84903  0.0480806
## EnjoyMath EnjoyMath   9.496719  2.071240   4.96789  13.97818 -0.1964301
## Resources Resources   6.500000  1.789419   0.00000   8.00000 -2.0198353
## Books         Books   2.708333  1.288954   1.00000   5.00000  0.2889950
##           Kurtosis
## MathScore 2.584527
## EnjoyMath 3.221936
## Resources 7.802098
## Books     2.023090