Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Focussing on {conmat}

Nicholas Tierney njtierney

:octocat:
Focussing on {conmat}
View GitHub Profile
View conmat-v-prem.md
# comparison of Prem vs conmat for germany:

library(deSolve)
library(tidyverse)
library(conmat)
world_data <- socialmixr::wpp_age() %>%
  mutate(
    new_lower_age = if_else(lower.age.limit >= 75, 75L, lower.age.limit)
  ) %>%
View distributions.md
library(distributional)
library(tidyverse)

dat <- tibble(
  id = 1:10,
  mean = c(1:10),
  sd = c(1:10)
) %>% 
  mutate(dist = dist_normal(
View abs-brain-teaser.md
# ABS - what is statistically special about these numbers?
set_one <- c(5, 2, 7, 3, 5, 1)
set_two <- c(9, 6, 3, 5, 8, 6)

summary(set_one)
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#>   1.000   2.250   4.000   3.833   5.000   7.000
summary(set_two)
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
View exploring-updated-wpp-data.md
library(tidyverse)
library(ggforce)
wpp_020 <- readr::read_csv("https://gist.githubusercontent.com/njtierney/8b3b55cec0fe95f496b7047bf095fd5b/raw/5b31740a102198fa3f76105f5f994bfa16e3e7f5/wpp_020.csv")
#> Rows: 70854 Columns: 4
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): country
#> dbl (3): lower.age.limit, year, population
#> 
View wpp_018.csv
We can't make this file beautiful and searchable because it's too large.
country,lower.age.limit,year,population
Afghanistan,0,1950,1291621.9999999998
Afghanistan,0,1955,1353989
Afghanistan,0,1960,1538039
Afghanistan,0,1965,1759739
Afghanistan,0,1970,2022533
Afghanistan,0,1975,2323223
Afghanistan,0,1980,2475420
Afghanistan,0,1985,2246768
Afghanistan,0,1990,2339899
View wpp_020.csv
We can't make this file beautiful and searchable because it's too large.
country,lower.age.limit,year,population
AFRICA,0,1950,38705049
AFRICA,0,1955,44304214
AFRICA,0,1960,50491493
AFRICA,0,1965,57690110
AFRICA,0,1970,65452837
AFRICA,0,1975,75017430
AFRICA,0,1980,86666665.00000001
AFRICA,0,1985,98999023
AFRICA,0,1990,110362756
View corplot-facets.md
library(tidyverse)
library(visdat)

iris_tbl <- as_tibble(iris)

iris_tbl_nest <- iris_tbl %>% 
  group_nest(Species) %>% 
  mutate(
    vis_cor = map2(.x = data, .y = Species, function(.x, .y){
View deck-shuffle.md
# simulated probability of getting the same cards twice in a shuffled deck

hand <- as.integer(c(7,10,2,3,1))

deck <- 1:52

deck_draws <- replicate(
  n = 1e7,
  expr = {
View scales-is-awesome.md
library(scales)
percent(0.1)
#> [1] "10%"
percent(0.01)
#> [1] "1%"
percent(0.001)
#> [1] "0%"
percent(1)
#> [1] "100%"
View missing-data-things.md
library(palmerpenguins)

penguins[1:5, c(3)] <- -99
penguins[1:5, c(4)] <- -98

penguins
#> # A tibble: 344 × 8
#>    species island    bill_length_mm bill_depth_mm flipper_…¹ body_…² sex    year
#>    <fct>   <fct>              <dbl>         <dbl>      <int>   <int> <fct> <int>