Skip to content

Instantly share code, notes, and snippets.

``` r
# from https://github.com/ASKurz/non-linear-RCT/blob/master/Simulate%20the%20data.Rmd
library(tidyverse)
library(faux)
#>
#> ************
#> Welcome to faux. For support and examples visit:
#> https://debruine.github.io/faux/
#> - Get and set global package options with: faux_options()
@adam-binks
adam-binks / latexdiff.md
Created May 7, 2022 17:18
How to LaTeX diff your Overleaf project

How to LaTeX diff your Overleaf project

Set up local latex environment

Grab the two versions

  • Download the original version
    • Go to Overleaf > history > find the version > view single version > download project at this version
  • Download the current version
library(emmeans)
data(mtcars)
# in the example here, all models give the same point estimates and similar
# SEs because there is only a single, categorical, variable in the model.
# if you add a continuous predictor, they will no longer, because the relationship
# assumed by the model will be different for the three models!
m <- glm(am ~ vs, data = mtcars, family = binomial)
em1 <- emmeans(m, "vs")
#===============================================================================
# 2022-01-17 -- twitter
# c19 IFR vs normal mortality
# Ilya Kashnitsky, [email protected], @ikashnitsky
#===============================================================================
library(tidyverse)
library(magrittr)
library(hrbrthemes)
library(reticulate)
@noamross
noamross / coupling.R
Last active January 18, 2022 16:29
Calculating spatial correlations in a MRF
library(mgcv)
library(spdep)
library(sf)
library(ggplot2)
# Columbus crime data from mgcv/spdep
example(columbus)
# Make a neighborhood object compatible with mgcv's MRF
nb <- poly2nb(columbus)
library(tidyverse)
library(gapminder)
library(brms)
library(tidybayes)
# Bayes stuff
options(mc.cores = 4,
brms.backend = "cmdstanr")
# Countries to focus on (two per continent)
library(tidycensus)
library(tidyverse)
library(sf)
library(mapview)
library(crsuggest)
# Get data on median home value by block group in Fort Bend County
fort_bend_value <- get_acs(
geography = "block group",
variables = "B25077_001",
@jcheng5
jcheng5 / README.md
Last active November 13, 2024 05:46
Accepting POST requests from Shiny

Accepting POST requests from Shiny

(This post was motivated by a talk by @jnolis at CascadiaRConf 2021)

Recent versions of Shiny have an undocumented feature for handling POST requests that are not associated with any specific Shiny session. (Note that this functionality is missing our normal level of polish; it's a fairly low-level hook that I needed to make some things possible, but doesn't make anything easy.)

In a nutshell, it works by replacing your traditional ui object with a function(req), and then marking that function with an attribute indicating that it knows how to handle both GET and POST:

library(shiny)
library(tidycensus)
library(tigris)
library(ggiraph)
library(tidyverse)
us_median_age <- get_acs(
geography = "state",
variables = "B01002_001",
year = 2019,
survey = "acs5",
library(tigris)
library(sf)
# Get shapefile from UNL Drought Monitor
# https://droughtmonitor.unl.edu/data/shapefiles_m/USDM_20210427_M.zip
# Explode the shapes then shift geometry
drought <- st_read("USDM_20210427.shp") %>%
st_cast("POLYGON") %>%
shift_geometry()