set.seed(123)
library(dplyr)
# Create dummy data
dummy_data <- data.frame(
years_education = rnorm(100, 12, 3), # Represents years of education
gender_female = rbinom(100, 1, 0.5), # 1 = Female, 0 = Male
household_wealth = sample(1:5, 100, replace = TRUE), # Wealth index from 1 to 5
district_code = sample(1:10, 100, replace = TRUE) # Represents district codes
) %>% arrange(district_code)
# Create HHid (Household ID), grouping every 3-4 records, and convert to character
dummy_data$HHid <- as.character(rep(1:20, each = 5, length.out = nrow(dummy_data)))
# Create a binary outcome variable for years of education
dummy_data$education_binary <- ifelse(dummy_data$years_education > 11, 1, 0)
# Define a logistic regression formula
formula <- education_binary ~ gender_female + household_wealth:gender_female
# Set the location and random effect variables
location_var <- "district_code"
random_effect_var <- "HHid"
# Run the mixed-effects logistic regression for a specific location (e.g., district 1)
result_single_glmre <- single_glmre2(dummy_data, formula, location_var, random_effect_var,
location_index = 1, family = binomial())
# View the result
print(result_single_glmre)
Run the code above in your browser using DataLab