#This is R code which was used to select the age bounds applied in the regression predicting the number of births in a given year. Based on visual observations of these results, the number of men and women over 18 have a significant impact on the number of births in a given year. However, Women loose significance around 28 while men lose significance around age 30. This information is applied to asses a new value which is the total number of men between the age of 18 and 30, and the number of women between 18 and 28, as a variable in the birth rate regression. This is later converted to be a variable which is the minimum number between the two groups, which provides more information than either the number of men or number of women alone.
##This code is not used in the simulation, but was used to create the birth rate model, which in turn is used in the simulation
library(tidyverse)
TEMP <- readRDS("../../Data/Cleaned_Data/Wyoming_County_Demographic_Data.Rds")  %>% mutate(Num_Male=log(Num_Male),Num_Female=log(Num_Female))
TEMP <- pivot_wider(TEMP,names_from=Age,values_from=c(Num_Male,Num_Female),names_prefix="Age_") %>% unique
#Establish good bounds for the birth groups
REG_DATA_PRLIM <- readRDS("../../Data/Cleaned_Data/Wyoming_County_Population.Rds") %>% mutate(Population=Population-Births+Deaths+Migration) %>% select(-Deaths,-Migration) %>% left_join(TEMP) %>% select(-Population,-Num_Male_Age_0,-Num_Female_Age_0)
  summary(lm(Births~. ,data=REG_DATA_PRLIM))
