Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

Commit

Permalink
look at 3rd axis in PCA
Browse files Browse the repository at this point in the history
  • Loading branch information
Aariq committed Jun 25, 2020
1 parent 542bff1 commit 4c2ff29
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion R/2-muir-analysis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ patchwork <-
plot_layout(guides = "collect") +
plot_annotation(tag_levels = "A") &
theme(panel.grid = element_blank()) &
labs(fill = "Precip. (mm)")
labs(fill = "Precip.\n(mm/yr)")
patchwork
ggsave(here("out", "muir-biplots.png"), width = 9, height = 4)
Expand Down
35 changes: 33 additions & 2 deletions R/5-model-stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ none.summary <-
full_join(none.pcr.summary) %>% full_join(none.pcr.auto.summary)
# write_excel_csv(none.summary, here("out", "none summary.csv"))

### how often is each axis significant?
none.anova <-
none.pcr.auto %>%
future_map("anova") %>%
bind_rows(.id = "dataset") %>%
group_by(term) %>%
summarize(n = n(),
n.sig = sum(p.value < 0.05),
`%p < 0.05` = n.sig/n*100)

rm(none.pls, none.pcr, none.pls.auto, none.pcr.auto)


Expand All @@ -53,6 +63,16 @@ apparent.summary <-
full_join(apparent.pcr.summary) %>% full_join(apparent.pcr.auto.summary)
# write_excel_csv(apparent.summary, here("out", "apparent summary.csv"))

### how often is each axis significant?
apparent.anova <-
apparent.pcr.auto %>%
future_map("anova") %>%
bind_rows(.id = "dataset") %>%
group_by(term) %>%
summarize(n = n(),
n.sig = sum(p.value < 0.05),
`%p < 0.05` = n.sig/n*100)

rm(apparent.pls, apparent.pcr, apparent.pls.auto, apparent.pcr.auto)


Expand All @@ -74,6 +94,16 @@ hidden.summary <-
full_join(hidden.pcr.summary) %>% full_join(hidden.pcr.auto.summary)
# write_excel_csv(hidden.summary, here("out", "hidden summary.csv"))

### how often is each axis significant?
hidden.anova <-
hidden.pcr.auto %>%
future_map("anova") %>%
bind_rows(.id = "dataset") %>%
group_by(term) %>%
summarize(n = n(),
n.sig = sum(p.value < 0.05),
`%p < 0.05` = n.sig/n*100)

rm(hidden.pls, hidden.pcr, hidden.pls.auto, hidden.pcr.auto)


Expand Down Expand Up @@ -117,5 +147,6 @@ outtable <-

write_excel_csv(outtable, here("out", "model statistics table.csv"), na = "-")



none.anova
apparent.anova
hidden.anova
1 change: 1 addition & 0 deletions R/6-simulation-figures.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ hidden.pls.bp <-
hidden.pls.bp
```


## Combine Biplots

I think I want 4 panels, PCA on the top, PLS on the bottom, apparent on the left, hidden on the right (to match figure 3)
Expand Down
7 changes: 5 additions & 2 deletions R/pcr.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ library(rsample)
library(purrr)
library(here)
library(lmtest)
library(broom)
library(car)

source(here("R", "ropls_helpers.R"))

#' Do PCA logistic regression (PCA-LR) using ropls::opls() and logistic glm.
Expand Down Expand Up @@ -91,8 +94,8 @@ pca_lr <- function(data, X_vars, Y_var, reg_pcs = "max", CV = 7, ...){
summarize(R2_tjur = diff(means), .groups = "drop_last") %>%
as.numeric(),
p.value = lik.test$`Pr(>Chisq)`[2])

return(list(pca = pca, scores = scores, glm = m, mod.stats = mod.stats, data = data))
marginal <- broom::tidy(car::Anova(m))
return(list(pca = pca, scores = scores, glm = m, mod.stats = mod.stats, data = data, anova = marginal))
}


Expand Down
Binary file modified out/muir-biplots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified out/simulation biplots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4c2ff29

Please sign in to comment.