Skip to content

Instantly share code, notes, and snippets.

Using pwiser

library(tidyverse)
if (!require(pwiser) ) remotes::install_github("brshallo/pwiser")

penguins <- palmerpenguins::penguins %>% na.omit()

t_test_statistic <- function(x, y){
 t.test(x, y) %&gt;% 
library(tidyverse)
library(logspline)
library(spatstat.core)

set.seed(123)
x <- rnorm(100)

# comparing speeds of building different CDF's
microbenchmark::microbenchmark(
library(tidyverse)

penguins <- palmerpenguins::penguins %>% na.omit()

### ACTUALLY THE BEST WAY TO DO THIS WOULD BE LIKE:
# penguins %>% 
#   group_nest(species, year) %>% 
#   pivot_wider(names_from = year,
#               values_from = data)
library(tidyverse)

defaultW <- getOption("warn")
options(warn = -1)

data(lending_club, package = "modeldata")
df_ca <- filter(lending_club, addr_state == "CA")
df_tx <- filter(lending_club, addr_state == "TX")
@brshallo
brshallo / cdf_density.R
Last active January 21, 2022 08:12
copied from deprecated spatstat:::CDF.density() function
# copied from spatstat.utils::paren()
paren <- function (x, type = "(") {
if (length(x) == 0)
return(x)
if (identical(type, ""))
type <- "blank"
switch(type, `(` = {
out <- paste("(", x, ")", sep = "")
}, `[` = {
out <- paste("[", x, "]", sep = "")
library(tidyverse)
set.seed(1234)
data <- map(1:3, ~runif(10)) %>%
set_names(paste0("x", 1:3)) %>%
as_tibble() %>%
mutate(letters = letters[1:10])
data
library(tidyverse)
library(Hmisc)

data(lending_club, package = "modeldata")
lending_club <- mutate(lending_club, funded_amnt = as.double(funded_amnt))

bootstap_grouped_weighted <- function(df, target, groups, wt){
  options(dplyr.summarise.inform = FALSE)
  
library(tidyverse)

# Setting-up example hiearchy data
rep_unlist <- function(vec, n){
  map(vec, rep, n) %>% unlist()
}

truth <- tibble(
  country = rep_unlist(c("USA", "Canada"), 4),
@brshallo
brshallo / many-models-example.md
Last active October 27, 2021 22:54
Example for R4DS book club
library(tidyverse)

mods_stats <- iris %>% 
  as_tibble() %>% 
  group_by(Species) %>% 
  nest() %>% 
  mutate(lm_mods = map(data, ~lm(Sepal.Length ~ Sepal.Width, data = .x))) %>% 
  mutate(summary_stats = map(lm_mods, broom::glance))
library(ggplot2)
library(dplyr)
library(purrr)

# Binomial distribution method
probs_survive <- 
  tibble(survivors = 1:16) %>% 
  mutate(prob = dbinom(16 - survivors, size = 18, prob = 0.5))