# Script 5: Internal Migration > Internal Migration is modeled calculating origin-destination matrices by age group and sex. For easier parameterization, parameters are split up in probabilities to leave and the distributions of destination by origin. ## File output The code below generates 3 model parameters stored in a Modgen .dat file - Migration probability by sex, age group and district - Migration destination by origin, sex, and age group - Turn module on/off ![*Figure: Internal Migration Parameters*](Figures/ParaMigration.png) ## Code ```{r, message=FALSE, warning=FALSE} #################################################################################################### # # DYNAMIS-POP Parameter Generation File 5 - Internal Migration # This file is generic and works for all country contexts. # Input file: globals_for_analysis.RData (To generate such a file run the setup script) # Last Update: Martin Spielauer 2018-06-29 # #################################################################################################### #################################################################################################### # Clear work space, load required packages and the input object file #################################################################################################### rm(list=ls()) library(haven) library(dplyr) library(data.table) library(sp) library(maptools) library(survival) library(fmsb) library(eha) load(file="globals_for_analysis.RData") dat <- g_residents_dat # Set Parameter Output File parafile <- file(g_para_migration, "w") # Constants n_maxdist <- max(dat$M_DOB) # Add an integer variable for age a year ago dat$m_ageago <- as.integer(dat$M_AGE)-1 # remove those not born a year ago dat <- dat[!(dat$m_ageago<0),] # Age groups 5 years ago, up to 60+ dat$m_agegr5 <- as.integer(dat$m_ageago/5) * 5 dat$m_agegr5[dat$m_agegr5>60] <- 60 # Remove those not in the country 12 months ago (previous district was max value of districts) dat <- dat[dat$M_PDIST