This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### Upgrade R - do this in R GUI, not RStudio IDE ---- | |
installr::updateR(TRUE) | |
#### Packages to install after R upgrade ---- | |
# CRAN | |
install.packages(c("devtools", "tidyverse", "installr", "readxl", "janitor", "broom", "lme4", "broom.mixed", "officer", "yaml", "here", "igraph", "kableExtra", "lubridate", "repmis", "tidyselect", "labelled", "withr", "naturalsort")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
factor_table <- function(x) tibble(key = str_split(x, "\\|")[[1]]) %>% | |
separate(key, into = c("key", "value"), sep = ",", extra = "merge") %>% | |
mutate(across(everything(), trimws)) | |
factor_convert <- function(x, d, dict) { | |
y <- factor_table(dict[dict$`Variable / Field Name` == cur_column(),]$`Choices, Calculations, OR Slider Labels`) | |
factor(x, levels = y$key, labels = y$value) | |
} | |
checkbox_labels <- function(x, dict) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <- function(d, est, se, p, expo = FALSE, dp = "%0.2f") { | |
mutate(d, | |
ci.lo = {{est}} - {{se}} * qnorm((1 + 0.95)/2), | |
ci.hi = {{est}} + {{se}} * qnorm((1 + 0.95)/2), | |
p.stars = case_when({{p}} < 0.001 ~ "***", | |
{{p}} < 0.01 ~ "**", | |
{{p}} < 0.05 ~ "*", | |
TRUE ~ ""), | |
across(c({{est}}, "ci.lo", "ci.hi"), ~case_when(expo ~ exp(.), TRUE ~ .)), | |
across(c({{est}}, "ci.lo", "ci.hi"), ~sprintf(dp, .)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Model Diagnostics | |
**Reference only, remove from report before sending to the sponsor** | |
### Influential Observations | |
```{r influence_plot, out.extra = "figure", echo = F, warning = F, message = F, comment = NA, eval = F} | |
influencePlot(mods$iris_data, id.method = "identify", main = "Influence Plot", sub = "Circle size is proportial to Cook's Distance" ) | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hist2 <- function(x) { | |
dat <- tibble(x = x) %>% | |
na.omit() | |
ggplot(dat, aes(x = x)) + | |
geom_histogram(aes(y =..density..), | |
bins = 30, | |
colour = "black", | |
fill = "white") + | |
stat_function(fun = dnorm, args = list(mean = mean(dat$x), sd = sd(dat$x))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### libraries ---- | |
# install.packages("intergraph") | |
library(dplyr) | |
library(purrr) | |
library(furrr) | |
library(GGally) | |
library(igraph) | |
library(stringdist) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paste_clip <- function(header = TRUE, ...) { | |
read.table("clipboard", sep = "\t", header = header, ...) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
copy_clip <- function(x, row.names = FALSE, col.names = TRUE, ...) { | |
write.table(x, "clipboard", sep = "\t", row.names = row.names, col.names = col.names, ...) | |
} |