# Path to results path.results<-"C:/Users/cpacioni/Documents/Wild dogs/NorthernArea/NorthernArea_Analysis_May2016/Dingo200IterAnalysis/Analysis_strategic_baiting" library("HexSimR") # ***NOTE*** # I have been removing or pasting in the folders for the ST depending on whether # I wanted to have these data in the outputs. # *********** #### Genetics #### # batch file to generate genepop files. Pass this to OutputTransformer.exe w.genepop.batch (path.results, scenarios="all", time.steps=c(30), pop.name="Dingoes", traits="PopID") system.time( multi.clean.genepop(path.results, scenarios="all", pop.name="Dingoes") ) # Calculate genetic distance system.time( multi.gen.dist(path.results, scenarios="all", pop.name="Dingoes") ) # calculate mean genetic distance system.time( m.gen.dist(path.results, scenarios = "all", pop.name="Dingoes", traits="PopID") ) # Genetic distance plot p<-gen.plot(path.results = path.results, pop.name = "Dingoes", time.step = 30, traits = "PopID") load(paste(path.results, "plot_gen_distance.rda", sep="/")) library(ggplot2) s<-c("DingoBase_Bait_Shoot05_Ag_hi", "DingoBase_Bait_Shoot05_Ag_low", "DingoBase", "DingoBase_Bait_Shoot10", "DingoBase_Bait_Shoot05", "DingoBase_Shoot10", "DingoBase_Shoot05", "DingoBaseSBF_Bait_Shoot05_Ag_hi", "DingoBaseSBF_Bait_Shoot05_Ag_low", "DingoBaseSBF_Strat_Bait_shoot5", # Strat baiting "DingoBaseSBF", "DingoBaseSBF_Bait_Shoot10", "DingoBaseSBF_Bait_Shoot05", "DingoBaseSBF_Shoot10", "DingoBaseSBF_Shoot05", "DingoBaseSBF_Strat_Bait_shoot10", # Strat baiting "DingoBaseSBF02_Bait_Shoot05_Ag_hi", "DingoBaseSBF02_Bait_Shoot05_Ag_low", "DingoBaseSBF02", "DingoBaseSBF02_Bait_Shoot10", "DingoBaseSBF02_Bait_Shoot05", "DingoBaseSBF02_Shoot10", "DingoBaseSBF02_Shoot05", "DingoBaseSBF05_Bait_Shoot05_Ag_hi", "DingoBaseSBF05_Bait_Shoot05_Ag_low", "DingoBaseSBF05", "DingoBaseSBF05_Bait_Shoot10", "DingoBaseSBF05_Bait_Shoot05", "DingoBaseSBF05_Shoot10", "DingoBaseSBF05_Shoot05") p[[1]]$Scenario<-s new_ord<-c("DingoBase", "DingoBaseSBF05", "DingoBaseSBF02", "DingoBaseSBF", "DingoBase_Shoot05", "DingoBaseSBF05_Shoot05", "DingoBaseSBF02_Shoot05", "DingoBaseSBF_Shoot05", "DingoBase_Shoot10", "DingoBaseSBF05_Shoot10", "DingoBaseSBF02_Shoot10", "DingoBaseSBF_Shoot10", "DingoBase_Bait_Shoot05", "DingoBaseSBF05_Bait_Shoot05", "DingoBaseSBF02_Bait_Shoot05", "DingoBaseSBF_Bait_Shoot05", "DingoBase_Bait_Shoot10", "DingoBaseSBF05_Bait_Shoot10", "DingoBaseSBF02_Bait_Shoot10", "DingoBaseSBF_Bait_Shoot10", "DingoBase_Bait_Shoot05_Ag_low", "DingoBaseSBF05_Bait_Shoot05_Ag_low", "DingoBaseSBF02_Bait_Shoot05_Ag_low", "DingoBaseSBF_Bait_Shoot05_Ag_low", "DingoBase_Bait_Shoot05_Ag_hi", "DingoBaseSBF05_Bait_Shoot05_Ag_hi", "DingoBaseSBF02_Bait_Shoot05_Ag_hi", "DingoBaseSBF_Bait_Shoot05_Ag_hi", "DingoBaseSBF_Strat_Bait_shoot5", # strat baiting "DingoBaseSBF_Strat_Bait_shoot10") p[[1]]$Scenario<-factor(p[[1]]$Scenario, levels=new_ord) p g<-p + theme_classic() + ylab("Mean genetic distance") + theme(legend.position="none", axis.text.x=element_text(angle=-90, hjust=0, vjust=0.3)) + theme(axis.line.x = element_line(color="black", size = 0.5), axis.line.y = element_line(color="black", size = 0.5)) # The last line is needed because of a bug in ggplot2.1 g dir_out<-"C:/Users/cpacioni/Documents/Wild dogs/NorthernArea/NorthernArea_Analysis_May2016/Dingo200IterAnalysis/Plots_strategic_baiting" dir.create(dir_out) ggsave(paste0(dir_out, "/", "plot_gen_dist_sorted.pdf"), plot=g, heigh=297, width=210, unit="mm") ggsave(paste0(dir_out, "/", "plot_gen_dist_sorted.jpeg"), plot=g, heigh=297, width=210, unit="mm") #### Reports #### # batch file to generate combined log files. Pass this to HexSimCommandLine.exe w.combine.log.batch(path.results, scenarios="all", dir.out=path.results) # Generate batch file for move and ranges reports. Pass this to OutputTransformer.exe system.time( report.batch(path.results, scenarios="all", ranges=TRUE, move=TRUE) ) # After reports are generated... multi.reports(path.results, scenarios="all", pop.name="Dingoes", type="move", all=TRUE, hx=NULL, events=NULL, start="min", end="max") multi.reports(path.results, scenarios="all", pop.name="Dingoes", type="ranges", all=TRUE, hx=1122.4, events=c("Lonersexplore", "Adjustterritories2"), start="min", end="max") system.time( SSMD.ranges(path.results, scenarios="all", base="DingoBase_SelDist", sum.ranges="summary_ranges.xlsx") ) # I had run SSMD.move but I then discarded these because they were all not-sign #### Invasion front #### invasion.front(path.results, ncensus=3, value = 1, patch.width=3.6*4, scenarios = "all") p <- invasion.plot(fname = paste(path.results, "Invasion.front.xlsx", sep="/")) load(paste(path.results, "plot_invasion.rda",sep="/")) library(ggplot2) s<-c("DingoBase" , "DingoBase_Bait_Shoot10" , "DingoBase_Bait_Shoot05" , "DingoBase_Shoot10" , "DingoBase_Shoot05" , "DingoBaseSBF" , "DingoBaseSBF_Bait_Shoot10", "DingoBaseSBF_Bait_Shoot05" , "DingoBaseSBF_Shoot10", "DingoBaseSBF_Shoot05" , "DingoBaseSBF02" , "DingoBaseSBF02_Bait_Shoot10", "DingoBaseSBF02_Bait_Shoot05" , "DingoBaseSBF02_Shoot10" , "DingoBaseSBF02_Shoot05", "DingoBase_PreEmpt50" , "DingoBase_STSurvival", "DingoBase_Bait_Shoot05_Ag_hi" , "DingoBase_Bait_Shoot05_Ag_low", "DingoBaseSBF_Bait_Shoot05_Ag_hi" , "DingoBaseSBF_Bait_Shoot05_Ag_low", "DingoBaseSBF02_Bait_Shoot05_Ag_hi" , "DingoBaseSBF02_Bait_Shoot05_Ag_low", "DingoBaseSBF05_Bait_Shoot05_Ag_hi" , "DingoBaseSBF05_Bait_Shoot05_Ag_low", "DingoBaseSBF05" , "DingoBaseSBF05_Bait_Shoot10", "DingoBaseSBF05_Bait_Shoot05" , "DingoBaseSBF05_Shoot10", "DingoBaseSBF05_Shoot05", "DingoBaseSBF_Strat_Bait_shoot5", "DingoBaseSBF_Strat_Bait_shoot10") p[[1]]$Scenario<-s new_ord<-c("DingoBase_STSurvival", "DingoBase_PreEmpt50", # end of ST "DingoBase", "DingoBaseSBF05", "DingoBaseSBF02", "DingoBaseSBF", "DingoBase_Shoot05", "DingoBaseSBF05_Shoot05", "DingoBaseSBF02_Shoot05", "DingoBaseSBF_Shoot05", "DingoBase_Shoot10", "DingoBaseSBF05_Shoot10", "DingoBaseSBF02_Shoot10", "DingoBaseSBF_Shoot10", "DingoBase_Bait_Shoot05", "DingoBaseSBF05_Bait_Shoot05", "DingoBaseSBF02_Bait_Shoot05", "DingoBaseSBF_Bait_Shoot05", "DingoBase_Bait_Shoot10", "DingoBaseSBF05_Bait_Shoot10", "DingoBaseSBF02_Bait_Shoot10", "DingoBaseSBF_Bait_Shoot10", "DingoBase_Bait_Shoot05_Ag_low", "DingoBaseSBF05_Bait_Shoot05_Ag_low", "DingoBaseSBF02_Bait_Shoot05_Ag_low", "DingoBaseSBF_Bait_Shoot05_Ag_low", "DingoBase_Bait_Shoot05_Ag_hi", "DingoBaseSBF05_Bait_Shoot05_Ag_hi", "DingoBaseSBF02_Bait_Shoot05_Ag_hi", "DingoBaseSBF_Bait_Shoot05_Ag_hi", "DingoBaseSBF_Strat_Bait_shoot5", "DingoBaseSBF_Strat_Bait_shoot10") p[[1]]$Scenario<-factor(p[[1]]$Scenario, levels=new_ord) p g<-p + theme_classic() + ylab("Mean km/year") + theme(legend.position="none", axis.text.x=element_text(angle=-90, hjust=0, vjust=0.3)) + theme(axis.line.x = element_line(color="black", size = 0.5), axis.line.y = element_line(color="black", size = 0.5)) # The last line is needed because of a bug in ggplot2.1 g ggsave(paste0(dir_out, "/", "plot_invasion_sorted.pdf"), plot=g, heigh=297, width=210, unit="mm") ggsave(paste0(dir_out, "/", "plot_invasion_sorted.jpg"), plot=g, dpi=300, heigh=297, width=210, unit="mm") #### census file calculations #### #### total pop size inside and outside #### temp <- census.calc(path.results, ncensus=2, headers=c("Trait Index 2", "Trait Index 3"), var.name = "Inside", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=2, headers=c("Trait Index 4", "Trait Index 5"), var.name = "Outside", bin.f = "+", scenarios = "all") # Proportion of floaters temp<-census.calc(path.results, ncensus=2, headers=c("Trait Index 2", "Inside"), var.name = "PropFloat_In", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=2, headers=c("Trait Index 4", "Outside"), var.name = "PropFloat_Out", bin.f = "/", scenarios = "all") #### By gender#### #### Pre_breeding #### # Sum by gender temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 6", "Trait Index 7", "Trait Index 18", "Trait Index 19", "Trait Index 30", "Trait Index 31"), var.name = "Males_In", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 10", "Trait Index 11", "Trait Index 22", "Trait Index 23", "Trait Index 34", "Trait Index 35"), var.name = "Males_Out", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 4", "Trait Index 5", "Trait Index 16", "Trait Index 17", "Trait Index 28", "Trait Index 29"), var.name = "Females_In", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 8", "Trait Index 9", "Trait Index 20", "Trait Index 21", "Trait Index 32", "Trait Index 33"), var.name = "Females_Out", bin.f = "+", scenarios = "all") # Floaters temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 6", "Trait Index 18", "Trait Index 30"), var.name = "MalesFlo_In", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 10", "Trait Index 22", "Trait Index 34"), var.name = "MalesFlo_Out", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 4", "Trait Index 16", "Trait Index 28"), var.name = "FemalesFlo_In", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 8", "Trait Index 20", "Trait Index 32"), var.name = "FemalesFlo_Out", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("MalesFlo_In", "Males_In"), var.name = "PropMalesFlo_In", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("MalesFlo_Out", "Males_Out"), var.name = "PropMalesFlo_Out", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("FemalesFlo_In", "Females_In"), var.name = "PropFemalesFlo_In", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("FemalesFlo_Out", "Females_Out"), var.name = "PropFemalesFlo_Out", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 30", "Males_In"), var.name = "PropAdMalesFlo_In", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 34", "Males_Out"), var.name = "PropAdMalesFlo_Out", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 28", "Females_In"), var.name = "PropAdFemalesFlo_In", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("Trait Index 32", "Females_Out"), var.name = "PropAdFemalesFlo_Out", bin.f = "/", scenarios = "all") # Sex-ratios temp<-census.calc(path.results, ncensus=0, headers=c("Males_In", "Females_In"), var.name = "SexRatio_In", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=0, headers=c("Males_Out", "Females_Out"), var.name = "SexRatio_Out", bin.f = "/", scenarios = "all") #### By gender #### #### Post_breeding #### # Sum by gender temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 6", "Trait Index 7", "Trait Index 18", "Trait Index 19", "Trait Index 30", "Trait Index 31"), var.name = "Males_In", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 10", "Trait Index 11", "Trait Index 22", "Trait Index 23", "Trait Index 34", "Trait Index 35"), var.name = "Males_Out", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 4", "Trait Index 5", "Trait Index 16", "Trait Index 17", "Trait Index 28", "Trait Index 29"), var.name = "Females_In", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 8", "Trait Index 9", "Trait Index 20", "Trait Index 21", "Trait Index 32", "Trait Index 33"), var.name = "Females_Out", bin.f = "+", scenarios = "all") # Floaters temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 6", "Trait Index 18", "Trait Index 30"), var.name = "MalesFlo_In", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 10", "Trait Index 22", "Trait Index 34"), var.name = "MalesFlo_Out", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 4", "Trait Index 16", "Trait Index 28"), var.name = "FemalesFlo_In", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 8", "Trait Index 20", "Trait Index 32"), var.name = "FemalesFlo_Out", bin.f = "+", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("MalesFlo_In", "Males_In"), var.name = "PropMalesFlo_In", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("MalesFlo_Out", "Males_Out"), var.name = "PropMalesFlo_Out", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("FemalesFlo_In", "Females_In"), var.name = "PropFemalesFlo_In", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("FemalesFlo_Out", "Females_Out"), var.name = "PropFemalesFlo_Out", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 30", "Males_In"), var.name = "PropAdMalesFlo_In", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 34", "Males_Out"), var.name = "PropAdMalesFlo_Out", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 28", "Females_In"), var.name = "PropAdFemalesFlo_In", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("Trait Index 32", "Females_Out"), var.name = "PropAdFemalesFlo_Out", bin.f = "/", scenarios = "all") # Sex-ratios temp<-census.calc(path.results, ncensus=1, headers=c("Males_In", "Females_In"), var.name = "SexRatio_In", bin.f = "/", scenarios = "all") temp<-census.calc(path.results, ncensus=1, headers=c("Males_Out", "Females_Out"), var.name = "SexRatio_Out", bin.f = "/", scenarios = "all") #### Collate and plot census #### system.time( collate.census(path.results, scenarios="all") ) # Plot census # ST ST<-c("DingoBase_SelDist", "DingoBase_SelDist_STSurvival", "DingoBase_SelDist_PreEmpty50") census.plot(path.results, scenarios=ST, traits=c("Inside", "Outside"), ncensus=2, ngroups=1) census.plot(path.results, scenarios=ST, traits=c("PropFloat_In", "PropFloat_Out"), ncensus=2, ngroups=1) load("C:/Users/30373314/Documents/DAFWA/Wild dogs/PVA/Analysis/Dingo200IterAnalysis/Plots_ST/plots_census.2.group.1.rda") library(ggplot2) unique(p[[1]]$Scenario) p[[1]]$Scenario[p[[1]]$Scenario=="DingoBase_SelDist"]<-"DingoBase" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBase_SelDist_STSurvival"]<-"DingoBase_STSurvival" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBase_SelDist_PreEmpty50"]<-"DingoBase_PreEmpt50" new_ord<-c("DingoBase_STSurvival", "DingoBase_PreEmpt50", "DingoBase") p[[1]]$Scenario<-factor(p[[1]]$Scenario, levels=new_ord) p g<-p + theme_classic() + ylab("Mean population size") + theme(legend.position="none") g dir_out<-"C:/Users/30373314/Documents/DAFWA/Wild dogs/PVA/Analysis/Dingo200IterAnalysis/Plots_ST" ggsave(paste0(dir_out, "/", "plots_census.ST_sorted.pdf"), plot=g, heigh=80, width=150, unit="mm") ggsave(paste0(dir_out, "/", "plots_census.ST_sorted.jpeg"), plot=g, dpi=300, heigh=80, width=150, unit="mm") # note: I have removed the two ST folders to generate the plots without them p<-census.plot(path.results, scenarios="all", traits=c("Inside", "Outside"), ncensus=2, ngroups=4) p<-census.plot(path.results, scenarios="all", traits=c("PropFloat_In", "PropFloat_Out"), ncensus=2, ngroups=4) load("C:/Users/30373314/Documents/DAFWA/Wild dogs/PVA/Analysis/Dingo200IterAnalysis/Plots/Plots.census/plots_census.2.group.2.rda") library(ggplot2) unique(p[[1]]$Scenario) p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SD_Bait_shoot5_aghi"]<-"DingoBaseSBF_Bait_Shoot05_Ag_hi" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SD_Bait_shoot5_aglow"]<-"DingoBaseSBF_Bait_Shoot05_Ag_low" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SelDist"]<-"DingoBaseSBF" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SelDist_Bait_shoot10"]<-"DingoBaseSBF_Bait_Shoot10" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SelDist_Bait_shoot5"]<-"DingoBaseSBF_Bait_Shoot05" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SelDist_shoot10"]<-"DingoBaseSBF_Shoot10" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SelDist_shoot5"]<-"DingoBaseSBF_Shoot05" new_ord<-c("DingoBaseSBF_Bait_Shoot05_Ag_hi", "DingoBaseSBF_Bait_Shoot05_Ag_low", "DingoBaseSBF_Bait_Shoot05", "DingoBaseSBF_Bait_Shoot10", "DingoBaseSBF_Shoot05", "DingoBaseSBF_Shoot10", "DingoBaseSBF") p[[1]]$Scenario<-factor(p[[1]]$Scenario, levels=new_ord) p g<-p + theme_classic() + ylab("Mean population size") + theme(legend.position="none") g dir_out<-"C:/Users/30373314/Documents/DAFWA/Wild dogs/PVA/Analysis/Dingo200IterAnalysis/Plots/Plots.census" ggsave(paste0(dir_out, "/", "plots_census.SBF.pdf"), plot=g, heigh=297, width=210, unit="mm") pres<-p + ylab("Mean population size") pres ggsave(paste0(dir_out, "/", "plots_census.SBF.pres.jpeg"), plot=pres, dpi=300, heigh=297, width=210, unit="mm") # Prop Flot load("C:/Users/30373314/Documents/DAFWA/Wild dogs/PVA/Analysis/Dingo200IterAnalysis/Plots/Plots_PropFlot/plots_census.2.group.2.rda") p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SD_Bait_shoot5_aghi"]<-"DingoBaseSBF_Bait_Shoot05_Ag_hi" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SD_Bait_shoot5_aglow"]<-"DingoBaseSBF_Bait_Shoot05_Ag_low" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SelDist"]<-"DingoBaseSBF" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SelDist_Bait_shoot10"]<-"DingoBaseSBF_Bait_Shoot10" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SelDist_Bait_shoot5"]<-"DingoBaseSBF_Bait_Shoot05" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SelDist_shoot10"]<-"DingoBaseSBF_Shoot10" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_SelDist_shoot5"]<-"DingoBaseSBF_Shoot05" p[[1]]$Scenario<-factor(p[[1]]$Scenario, levels=new_ord) p g<-p + theme_classic() + ylab("Proportion of loners ") + theme(legend.position="none") + theme(axis.line.x = element_line(color="black", size = 0.5), axis.line.y = element_line(color="black", size = 0.5)) # The last line is needed because of a bug in ggplot2.1 g dir_out<-"C:/Users/30373314/Documents/DAFWA/Wild dogs/PVA/Analysis/Dingo200IterAnalysis/Plots/Plots_PropFlot" ggsave(paste0(dir_out, "/", "plots_PropFlot.SBF.pdf"), plot=g, heigh=297, width=210, unit="mm") ggsave(paste0(dir_out, "/", "plots_PropFlot.SBF.tiff"), plot=g, heigh=297, width=210, unit="mm") library(ggplot2) p<-p[[1]] unique(p[[1]]$Scenario) p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF_AD_Bait_shoot5_aghi"]<-"DingoBaseSBF_Bait_Shoot05_Ag_hi" p[[1]]$Scenario[p[[1]]$Scenario=="DingoBaseSBF05_NoAgD_Bait_shoot5_aghi"]<-"DingoBaseSBF05_NoAg_Bait_Shoot05_Ag_hi" new_ord<-c("DingoBaseSBF_Bait_Shoot05_Ag_hi", "DingoBaseSBF05_NoAg_Bait_Shoot05_Ag_hi") p[[1]]$Scenario<-factor(p[[1]]$Scenario, levels=new_ord) p g<-p + theme_classic() + ylab("Mean population size") + theme(legend.position="none") + theme(axis.line.x = element_line(color="black", size = 0.5), axis.line.y = element_line(color="black", size = 0.5)) g dir_out<-path.results ggsave(paste0(dir_out, "/", "plots_census.AD.pdf"), plot=g, heigh=297, width=210, unit="mm") ggsave(paste0(dir_out, "/", "plots_census.AD.jpeg"), plot=g, heigh=110, width=161, unit="mm") pres<-p + ylab("Mean population size") pres ggsave(paste0(dir_out, "/", "plots_census.AD.pres.jpeg"), plot=g, dpi=300, heigh=297, width=210, unit="mm") #### SSMD census #### # I first create some helper functions to process all ssdm at once for each group # of comparisons #######################Helper FUNs########################## f.move<-function(f.name, wspace, dir.out) { file.copy(from=f.name, to=paste(wspace, dir.out, sep="/") ) } apply.ssmd<-function(scen, path.results, ncs, suf, base) { lapply(ncs, SSMD.census, path.results=path.results, scenarios=scen, base=base) dir.out<-paste("SSMD.census", suf, sep=".") wspace <- sub(pattern = "Results", replacement = "", path.results) dir.create(paste(wspace, dir.out, sep="/")) file.list<-list.files(path = path.results, pattern = "^SSMD_census", full.names = T) lapply(file.list, f.move, wspace, dir.out=dir.out) lapply(file.list, file.remove) } #######################End Helper FUNs######################### # ST ncs <- 0:2 ST<-c("DingoBase_SelDist", "DingoBase_SelDist_STSurvival", "DingoBase_SelDist_PreEmpty50") system.time( apply.ssmd(scen=ST, path.results, ncs, suf="ST", base=ST[1]) ) # Grouped by fence permeability ncs <- 0:2 NoSBF<-c("DingoBase_SelDist" , "DingoBase_SelDist_Bait_shoot10", "DingoBase_SelDist_Bait_shoot5", "DingoBase_SD_Bait_shoot5_aglow", "DingoBase_SD_Bait_shoot5_aghi", "DingoBase_SelDist_shoot10", "DingoBase_SelDist_shoot5") SBF<-c("DingoBaseSBF_SelDist", "DingoBaseSBF_SelDist_Bait_shoot10", "DingoBaseSBF_SelDist_Bait_shoot5", "DingoBaseSBF_SD_Bait_shoot5_aglow", "DingoBaseSBF_SD_Bait_shoot5_aghi", "DingoBaseSBF_SelDist_shoot10", "DingoBaseSBF_SelDist_shoot5", "DingoBaseSBF_SD_Strat_Bait_shoot5", "DingoBaseSBF_SelDist_Strat_Bait_shoot10") SBF02<-c("DingoBaseSBF02_SelDist" , "DingoBaseSBF02_SelDist_Bait_shoot10", "DingoBaseSBF02_SelDist_Bait_shoot5", "DingoBaseSBF02_SD_Bait_shoot5_aglow", "DingoBaseSBF02_SD_Bait_shoot5_aghi", "DingoBaseSBF02_SelDist_shoot10", "DingoBaseSBF02_SelDist_shoot5") SBF05<-c("DingoBaseSBF05_SelDist", "DingoBaseSBF05_SelDist_Bait_shoot10", "DingoBaseSBF05_SelDist_Bait_shoot5", "DingoBaseSBF05_SD_Bait_shoot5_aglow", "DingoBaseSBF05_SD_Bait_shoot5_aghi", "DingoBaseSBF05_SelDist_shoot10", "DingoBaseSBF05_SelDist_shoot5") system.time( apply.ssmd(scen="all", path.results, ncs, suf="all", base=SBF[1]) ) apply.ssmd(scen=NoSBF, path.results, ncs, suf="NoSBF", base=NoSBF[1]) apply.ssmd(scen=SBF, path.results, ncs, suf="SBF", base=SBF[1]) apply.ssmd(scen=SBF02, path.results, ncs, suf="SBF02", base=SBF02[1]) apply.ssmd(scen=SBF05, path.results, ncs, suf="SBF05", base=SBF05[1]) # Grouped by management option ncs <- 0:2 NoControl<-c("DingoBase_SelDist", "DingoBaseSBF_SelDist", "DingoBaseSBF02_SelDist", "DingoBaseSBF05_SelDist") Bait_shoot10<-c("DingoBase_SelDist_Bait_shoot10", "DingoBaseSBF_SelDist_Bait_shoot10", "DingoBaseSBF02_SelDist_Bait_shoot10", "DingoBaseSBF05_SelDist_Bait_shoot10") Bait_shoot05<-c("DingoBase_SelDist_Bait_shoot5", "DingoBaseSBF_SelDist_Bait_shoot5", "DingoBaseSBF02_SelDist_Bait_shoot5", "DingoBaseSBF05_SelDist_Bait_shoot5") Shoot10<-c("DingoBase_SelDist_shoot10", "DingoBaseSBF_SelDist_shoot10", "DingoBaseSBF02_SelDist_shoot10", "DingoBaseSBF05_SelDist_shoot10") Shoot05<-c("DingoBase_SelDist_shoot5", "DingoBaseSBF_SelDist_shoot5", "DingoBaseSBF02_SelDist_shoot5", "DingoBaseSBF05_SelDist_shoot5") Bait_shoot05_ag_low<-c("DingoBase_SD_Bait_shoot5_aglow", "DingoBaseSBF_SD_Bait_shoot5_aglow", "DingoBaseSBF02_SD_Bait_shoot5_aglow", "DingoBaseSBF05_SD_Bait_shoot5_aglow") Bait_shoot05_ag_hi<-c("DingoBase_SD_Bait_shoot5_aghi", "DingoBaseSBF_SD_Bait_shoot5_aghi", "DingoBaseSBF02_SD_Bait_shoot5_aghi", "DingoBaseSBF05_SD_Bait_shoot5_aghi") apply.ssmd(scen=NoControl, path.results, ncs, suf="NoControl", base=NoControl[1]) apply.ssmd(scen=Bait_shoot10, path.results, ncs, suf="Bait_shoot10", base=Bait_shoot10[1]) apply.ssmd(scen=Bait_shoot05, path.results, ncs, suf="Bait_shoot05", base=Bait_shoot05[1]) apply.ssmd(scen=Shoot10, path.results, ncs, suf="Shoot10", base=Shoot10[1]) apply.ssmd(scen=Shoot05, path.results, ncs, suf="Shoot05", base=Shoot05[1]) apply.ssmd(scen=Bait_shoot05_ag_low, path.results, ncs, suf="Bait_shoot05_ag_low", base=Bait_shoot05_ag_low[1]) apply.ssmd(scen=Bait_shoot05_ag_hi, path.results, ncs, suf="Bait_shoot05_ag_hi", base=Bait_shoot05_ag_hi[1]) #### Copy results #### # copy all SSMD_census in a saparate folder outside path.results # These results don't have normal HexSimR layout because I have created them with # a function (above) that removed the results as they were created into a folder # because otherwise these would have been overwritten. I'll use this sub-folder # structure below to contruct the tables. SSMD_census_fold<-"C:/Users/cpacioni/Documents/Wild dogs/NorthernArea/NorthernArea_Analysis_May2016/Dingo200IterAnalysis/SSMD.census_strategic_baiting" dir.create(SSMD_census_fold) setwd(path.results) fold_lilst<-list.dirs() fold_lilst<-fold_lilst[grep("SSMD.census*.", x = fold_lilst)] file.copy(fold_lilst, to=SSMD_census_fold, recursive = T) unlink(fold_lilst, recursive=T) # Path to back up destination dir.out<-"\\\\10.0.0.1\\Public\\Carlo\\DingoPVA\\Dingo200IterAnalysis\\Analysis" copy.results(path.results, out = dir.out, copy.invasion = TRUE, comp.census = F, comp.move = F, comp.ranges = F, plots = T, scen.results = TRUE, scenarios = "all") #### Make table #### # Table descriptive results table <- make.table(path.results, scenarios="all", fnames=paste0( 2:1, ".all.xlsx"), SSMD=FALSE, colh=list(c("Inside", "Outside", "PropFloat_In", "PropFloat_Out"), c("SexRatio_In", "SexRatio_Out")), vround=1, sdround=2, time.steps=c(5, 30), table.name="Tables.xlsx", tab.name="Dem_descrip", save2disk=TRUE, dir.out=NULL) # The following four lines remove the base scenario NoSBF<-NoSBF[-1] SBF<-SBF[-1] SBF02<-SBF02[-1] SBF05<-SBF05[-1] # This group the scenarios for each comparison in a list g<-list(NoSBF, SBF, SBF02, SBF05) # Creates a vector with the path where the SSMD_census subfolders are path.SSMD.subfolders<-paste(SSMD_census_fold, fold_lilst[6:9], sep="/") # The following creates a function that passes to make.table one element at the time # from g and path.SSMD.subfolders created above base on an index i # NOTE that fence permeability is in the same order in g and path.SSMD.subfolders # Also, note that file names and colh are hard coded, but these can be changed # wither in the function before sourcing it or programmatically # (i.e. as function's arguments) pass.make.table <- function(i, path.SSMD.subfolders, g) { make.table(path.results=path.SSMD.subfolders[i], scenarios=g[[i]], fnames=c("SSMD_census2.xlsx", "SSMD_census1.xlsx"), SSMD=TRUE, colh=list(c("Inside", "Outside", "PropFloat_In", "PropFloat_Out"), c("SexRatio_In", "SexRatio_Out")), vround=3, sdround=3, time.steps=c(5,30), table.name="Tables.xlsx", tab.name="SSMD_dem", save2disk=TRUE, dir.out=NULL) } l<-lapply(1:4, pass.make.table, path.SSMD.subfolders, g) # load data.table if not already library(data.table) data<-rbindlist(l, use.names = T) library(XLConnect) wb <- loadWorkbook("Tables.xlsx", create=TRUE) createSheet(wb, name="SSMD_dem_pval") writeWorksheet(wb, data, sheet="SSMD_dem_pval") saveWorkbook(wb) # Ranges path.results<-"C:/Users/cpacioni/Documents/Wild dogs/NorthernArea/NorthernArea_Analysis_May2016/Dingo10IterAnalysis/Results" # remove strategic baiting scenarios because these where not included in the # SSMD ranges analysis SBF<-SBF[1:6] # create a vector with the names of the scenairos scens<-c(NoSBF, SBF, SBF02, SBF05) # Create the table. NOTE that time.steps=NULL (default) because these are already # subsetted when the SSMD comparison is done table <- make.table(path.results, scenarios=scens, fnames="SSMD_ranges.xlsx", SSMD=TRUE, colh=list(c("GroupSize", "Resources", "nGroups", "sqkm")), vround=3, sdround=2, time.steps=NULL, table.name="Tables.xlsx", tab.name="SSMD_pval_Ranges", save2disk=TRUE, dir.out=NULL) # SSMD for Move statistics table <- make.table(path.results, scenarios=scens, fnames="SSMD_move.xlsx", SSMD=TRUE, colh=list(c("X.Dispersal.male.floaters", "X.Dispersal.female.floaters", "X.Dispersal.adult.and.juv.males.from.pack", "X.Dispersal.adult.and.juv.females.from.pack")), vround=3, sdround=2, time.steps=NULL, table.name="Tables.xlsx", tab.name="SSMD_pval_move", save2disk=TRUE, dir.out=NULL)