Replm2: Run Regression Analysis for All Locations

View source: R/hello.R

Replm2R Documentation

Run Regression Analysis for All Locations

Description

This function runs a regression model for all unique locations within a dataset and combines the results.

Usage

Replm2(
  data,
  formula,
  location_var,
  response_distribution = "normal",
  family = NULL
)

Arguments

data

The dataset to be analyzed.

formula

The formula for the regression model.

location_var

The variable indicating different locations (e.g., 'REGCODE').

response_distribution

The distribution of the response variable ("normal" for normal distribution, "other" for other distributions).

family

The family to be used for GLM if response_distribution is "other" (e.g., 'binomial' for logistic regression).

Value

A dataframe containing the combined results for all locations.

Examples

set.seed(123)
library(dplyr)
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)

# Define a simple regression formula
formula <- years_education ~ gender_female + household_wealth + household_wealth:gender_female

# Run the regression across all locations (districts)
results1 <- Replm2(dummy_data, formula, "district_code", "normal")
print(results1)

DHSr documentation built on April 4, 2025, 12:18 a.m.