This file contains hidden or 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
use [database]; | |
select * from INFORMATION_SCHEMA.tables; |
This file contains hidden or 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
When you get this error or similar: | |
`error in `db_copy_to()`: can't copy data to table ... ` | |
Check the installed version of DBI in R. You may need to install an earlier version (1.1.3 has worked in the past) instead of anything later than that. | |
You can do this using: | |
devtools::install_version("DBI", version = "1.1.3") |
This file contains hidden or 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
table |> | |
cols_label_with(fn = ~md(glue::glue("**{.}**"))) |
This file contains hidden or 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
labelled::set_variable_labels( | |
.labels = set_names( | |
as.list(dic$field_label), # label | |
dic$field_name # column name | |
), | |
.strict = FALSE | |
) |
This file contains hidden or 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
#' Rubin's Rules | |
#' | |
#' @param x A data.frame or similar containing one column of imputed point estimates and one column of imputed standard errors | |
#' @param estims character; name of the column in \code{x} containing imputed point estimates | |
#' @param stds character; name of column in \code{x} containing imputed standard errors | |
#' | |
#' @return A data.frame with two columns containing one row each: theta, the aggregate point estimate; and std.error, the aggregate standard error | |
#' | |
#' @examples | |
rubins_rules <- function(x, estims, stds) { |
This file contains hidden or 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
tbl |> | |
modify_header(label = "") |
This file contains hidden or 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
```{r} | |
# Function to create tabs - we'll iterate over this | |
# Uses Pandoc's div structure (where ::: is analogous to RMarkdown's #) and panel structure (using {.panel}) | |
make_tab <- function(tab_name) { | |
cat("::: {.panel}\n") # Open tab | |
cat("##", as.character(tab_name), "{.panel-name}\n") # Label tab |
This file contains hidden or 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
# Sometimes, due to convergence issues, Fisher's Exact Test will exclude a p-value from a tbl_summary() table. | |
# To get around this, create a custom stat that will be used in your tbl_summary() call: | |
fisher_sim_p <- function(data, variable, by, ...) { | |
result <- list() | |
result$p <- stats::fisher.test(x = data %>% pull({{variable}}), y = data %>% pull({{by}}), simulate.p.value = T)$p.value | |
result$test <- "Fisher's test with simulated p-value" | |
result | |
} |
This file contains hidden or 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
# If you want to annotate a faceted ggplot (e.g., one that uses facet_wrap() to facet across a factor variable), use the following form: | |
# first, create a dataframe to contain your annotation for each facet, making sure to include a column for the facet it'll be included in | |
ann_text <- data.frame(year = rep(2006, 3), | |
n = rep(2000000, 3), | |
x = c(2005, 2005, 2010), | |
y = rep(1750000, 3), | |
xend = c(2001, 1998, 2020), | |
yend = c(1157, 75621, 101503), | |
lab = c("Office visits go back to\napproximately 2001.", |
This file contains hidden or 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
library(crimCV) | |
library(dplyr) | |
library(ggplot2) | |
# load toy data included with crimCV package | |
data(TO1adj) | |
# fitting model - don't need to run this, but helpful if need toy data to plot | |
out1 <- crimCV(TO1adj, 2, dpolyp = 2, rcv = TRUE) |
NewerOlder