Replm2 | R Documentation |
This function runs a regression model for all unique locations within a dataset and combines the results.
Replm2(
data,
formula,
location_var,
response_distribution = "normal",
family = NULL
)
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). |
A dataframe containing the combined results for all locations.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.