Skip to content

Commit

Permalink
fix PCA
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsla committed Nov 16, 2023
1 parent 30e2e76 commit 65f2203
Show file tree
Hide file tree
Showing 14 changed files with 6,059 additions and 6,045 deletions.
12,088 changes: 6,044 additions & 6,044 deletions data/model_data.csv

Large diffs are not rendered by default.

Binary file modified predictions/C_infuscatellus.tif
Binary file not shown.
Binary file modified predictions/E_flavipes.tif
Binary file not shown.
Binary file modified predictions/P_saccharicida.tif
Binary file not shown.
Binary file modified predictions/S_excerptalis.tif
Binary file not shown.
Binary file modified predictions/S_grisescens.tif
Binary file not shown.
Binary file modified predictions/Y_flavovittatus.tif
Binary file not shown.
Binary file modified predictions_binary/C_infuscatellus.gpkg
Binary file not shown.
Binary file modified predictions_binary/E_flavipes.gpkg
Binary file not shown.
Binary file modified predictions_binary/P_saccharicida.gpkg
Binary file not shown.
Binary file modified predictions_binary/S_excerptalis.gpkg
Binary file not shown.
Binary file modified predictions_binary/S_grisescens.gpkg
Binary file not shown.
Binary file modified predictions_binary/Y_flavovittatus.gpkg
Binary file not shown.
16 changes: 15 additions & 1 deletion sdm.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ set.seed(4326)
pca <- values(spatSample(rst, 100000, as.raster=TRUE)) %>%
na.omit() %>%
as.data.frame() %>%
prcomp()
prcomp(scale. = T)
plot(pca)

rast_pca <- predict(rst, pca)
Expand Down Expand Up @@ -394,6 +394,20 @@ summary(modelPS)
# gratia::draw(modelPS)
plot(modelPS, pages = 1, rug = FALSE, shade = TRUE)

gratia::smooth_estimates(modelPS) %>%
filter(str_detect(smooth, "species")) %>%
mutate(smooth = case_when(str_detect(smooth, "PC1") ~ "PC1",
str_detect(smooth, "PC2") ~ "PC2",
str_detect(smooth, "PC3") ~ "PC3",
str_detect(smooth, "PC4") ~ "PC4")) %>%
pivot_longer(c(6,8:10)) %>%
ggplot(aes(x = value, y = est, colour = species)) +
geom_line(linewidth = 1) +
facet_wrap(~name, scales = "free") +
theme_minimal() +
scale_colour_viridis_d(option = "inferno") +
theme(legend.position = "bottom") + labs(x = "", y = "")

gam.check(modelPS)

test_df <- model_data[-trainIndex,] %>%
Expand Down

0 comments on commit 65f2203

Please sign in to comment.