Skip to content

Commit

Permalink
Add Code Not Data
Browse files Browse the repository at this point in the history
  • Loading branch information
gfalbery committed Dec 3, 2019
1 parent b028535 commit 4ada013
Show file tree
Hide file tree
Showing 68 changed files with 13,835 additions and 255 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
.data
.Iceberg December Saves
5,403 changes: 5,403 additions & 0 deletions Data for dispersal_Corrected.csv

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Greg GAM Code/0_Master Iceberg.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#source("02_Iceberg ENM Futures.R")

print("Spatial!")
source("Final Iceberg Code/1_Iceberg Spatial.R")
# source("Final Iceberg Code/1_Iceberg Spatial.R")

print("Data Import!")
source("Final Iceberg Code/2_Iceberg Data Import.R")
Expand Down
2 changes: 1 addition & 1 deletion Greg GAM Code/2_Iceberg Data Import.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ NonEutherianSp <- Panth1[Panth1$hOrder%in%NonEutherians,"Sp"]

tFullSTMatrix <- 1 -
(FullSTMatrix[!rownames(FullSTMatrix)%in%NonEutherianSp,!rownames(FullSTMatrix)%in%NonEutherianSp] -
min(FullSTMatrix[!rownames(FullSTMatrix)%in%NonEutherianSp,!rownames(FullSTMatrix)%in%NonEutherianSp]))/
min(FullSTMatrix[!rownames(FullSTMatrix)%in%NonEutherianSp,!rownames(FullSTMatrix)%in%NonEutherianSp]))/
max(FullSTMatrix[!rownames(FullSTMatrix)%in%NonEutherianSp,!rownames(FullSTMatrix)%in%NonEutherianSp])

tSTMatrix <- tFullSTMatrix
Expand Down
8 changes: 4 additions & 4 deletions Greg GAM Code/3_Iceberg GAMs.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ if(Output){

plot_grid(FitList[[Pipeline]] %>%
filter(!is.na(SpaceQuantile)) %>%
ggplot(aes(Phylo, Fit, colour = SpaceQuantile)) +
ggplot(aes(Phylo, Fit, colour = SpaceQuantile)) + theme_cowplot() +
geom_ribbon(aes(ymin = Lower, ymax = Upper, fill = SpaceQuantile), alpha = 0.2, colour = NA) +
geom_line(aes(group = as.factor(Space))) +
labs(y = "Viral sharing probability", x = "Phylogenetic similarity",
Expand All @@ -183,7 +183,7 @@ if(Output){

FitList[[Pipeline]] %>%
filter(!is.na(PhyloQuantile)) %>%
ggplot(aes(Space, Fit, colour = PhyloQuantile)) +
ggplot(aes(Space, Fit, colour = PhyloQuantile)) + theme_cowplot() +
geom_ribbon(aes(ymin = Lower, ymax = Upper, fill = PhyloQuantile), alpha = 0.2, colour = NA) +
geom_line(aes(group = as.factor(Phylo))) +
labs(y = "Viral sharing probability", x = "Geographic overlap",
Expand All @@ -200,7 +200,7 @@ if(Output){
FitList[[Pipeline]] %>%
filter(!Phylo == last(unique(Phylo)),
!Space == last(unique(Space))) %>%
ggplot(aes(Space, Phylo)) +
ggplot(aes(Space, Phylo)) + theme_cowplot() +
geom_tile(aes(fill = Fit)) +
labs(x = "Geographic overlap",
y = "Phylogenetic similarity",
Expand All @@ -217,7 +217,7 @@ if(Output){
breaks = c(0,0.5,1)),

DataList[[Pipeline]] %>%
ggplot(aes(Space, Phylo)) +
ggplot(aes(Space, Phylo)) + theme_cowplot() +
labs(x = "Geographic overlap",
y = "Phylogenetic similarity") +
#ggtitle("Data Distribution") +
Expand Down
31 changes: 8 additions & 23 deletions Greg GAM Code/4_Iceberg Prediction.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ AllMammalMatrix[,SpaceVars] <-

}) %>% bind_cols

for(i in 1:length(PipelineReps)){

AllMammalMatrix[, paste0("Delta", SpaceVars[1:4 + (i-1)*4])] <-

apply(AllMammalMatrix[, SpaceVars[1:4 + (i-1)*4]], 2, function(a) a - AllMammalMatrix[ , paste0("Space.Currents", PipelineReps[i])])

}

UpperMammals <- which(upper.tri(tFullSTMatrix[AllMammals, AllMammals], diag = T))

AllMammaldf <- AllMammalMatrix[-UpperMammals,]
Expand Down Expand Up @@ -153,16 +145,12 @@ for(Pipeline in PipelineReps){

AllMammaldf2 <- AllMammaldf %>% dplyr::select(-Spp)

saveRDS(AllMammaldf2, file = "Iceberg Output Files/AllMammaldf.rds")

}

}

AllMammaldf <- AllMammaldf %>% dplyr::select(-Spp)

save(AllMammaldf, file = paste0("Iceberg Output Files/AllMammaldf.Rdata"))

for(i in 1:length(PipelineReps)){

AllMammaldf[, paste0("Delta", SpaceVars[2:5 + (i-1)*5])] <-
Expand Down Expand Up @@ -206,16 +194,16 @@ NewEncountersList <-

names(NewEncountersList) <- PipelineReps

# Making new encounters ####
# Making old encounters ####

NewEncountersList <-
OldEncountersList <-

lapply(PipelineReps, function(b){

l1 <- lapply(PredReps[2:5], function(a){

AllMammaldf[AllMammaldf[,paste0("Space.Currents",b)]==0&
AllMammaldf[,paste0("Space.", a, b)]>0,]
AllMammaldf[AllMammaldf[,paste0("Space.Currents",b)]>0&
AllMammaldf[,paste0("Space.", a, b)]==0,]

})

Expand All @@ -225,11 +213,8 @@ NewEncountersList <-

})

names(NewEncountersList) <- PipelineReps

save(AllMammaldf, file = paste0("Iceberg Output Files/AllMammaldf.Rdata"))
save(NewEncountersList, file = paste0("Iceberg Output Files/NewEncounters.Rdata"))

??pivot_wider

names(OldEncountersList) <- PipelineReps

saveRDS(AllMammaldf, file = "Iceberg Output Files/AllMammaldf.rds")
saveRDS(NewEncountersList, file = paste0("Iceberg Output Files/NewEncounters.rds"))
saveRDS(OldEncountersList, file = paste0("Iceberg Output Files/OldEncounters.rds"))
Loading

0 comments on commit 4ada013

Please sign in to comment.