Skip to content

Instantly share code, notes, and snippets.

View njtierney's full-sized avatar
🐝
Back at work

Nicholas Tierney njtierney

🐝
Back at work
View GitHub Profile
---
title: example multi figures
format: html
---
We can also see that there is an interesting relationship between Ozone and temperature.
```{r}
#| label: fig-aq
#| fig-cap:
library(tidyverse)

group <- tribble(
  ~group,           ~golding, ~senior, ~hao,  ~windecker, ~tierney,  ~stretton, ~chikolwa, ~duncan, ~ryan, ~avenell, ~shearer, ~ohiolel, ~saraswati,
   "KRIA",           TRUE,     TRUE,   TRUE,  TRUE,       TRUE,      TRUE,      TRUE,      TRUE,    TRUE,  TRUE,     TRUE,     TRUE,    TRUE,
   "CHA",            TRUE,     TRUE,   TRUE,  TRUE,       TRUE,      TRUE,      TRUE,      TRUE,    TRUE,  FALSE,     TRUE,     TRUE,    TRUE,
   "IDEM",           TRUE,     TRUE,   TRUE,  TRUE,       TRUE,      TRUE,      TRUE,      TRUE,    TRUE,  FALSE,     TRUE,     TRUE,    TRUE,
   "IDDU",           TRUE,     TRUE,   TRUE,  TRUE,       TRUE,      TRUE,      TRUE,      TRUE,    TRUE,  FALSE,     TRUE,     TRUE,    TRUE,
   "IIDM",           TRUE,    FALSE,  FALSE, FALSE,      FALSE,     FALSE,     FALSE,     FALSE,   FALSE,  FALSE,    FALSE,    FALSE,   FALSE,

This was code originally written by Nick Golding, in August 2022.

It was initially written to demonstrate using symmetrical terms and the benefit of them in conmat.

They handily demonstrate a nice plot of the different terms in a gam - effectively giving us a "contact matrix" of the effect of each term. The part where that happens is where predict is used inside mutate.

library(mgcv)
#> Loading required package: nlme
#> This is mgcv 1.9-1. For overview type 'help("mgcv-package")'.
library(greta)
#> 
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#> 
#>     binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#> 
#>     %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
# blog post?

my_mean <- function(x, ...) mean(x, na.rm = TRUE, ...)

vec <- c(1:5, NA, 5:1)

my_mean(vec)
#> [1] 3
my_mean(vec, na.rm = TRUE)
library(tibble)
library(tidyverse)
ihr_car_ratio <- greta::uniform(0,1)
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✔ Initialising python and checking dependencies ... done!
#> 

ihr_car_ratio
#> greta array (variable following a uniform distribution)
# something like this?
library(tidyverse)
library(lobstr)
existing_data_list <- list(
  data.frame(x = 1:5, y = 0),
  data.frame(z = 5:1),
  data.frame(y = 1:5, a = 2)
)
library(conmat)
library(socialmixr)
library(tidyverse)
countries_of_interest <- c("Italy", "Spain")
list_countries <- map(countries_of_interest,
\(x) wpp_age(x, years = 2015))
list_conmat_pop <- map(
.x = list_countries,
bee_trips <- 1:10

sample(bee_trips,
       size = 100,
       replace = TRUE)
#>   [1]  2  4  5  2  3  7  5  8  5  7  6  2  8  4 10  6  2  3 10  4  6  8  9  5  6
#>  [26]  6  8  7  6  8  5  4  7  5  6  3  5  3  7  1  9  4  8  7  8  3 10  3  5 10
#>  [51] 10  5  8  6  2  6  6  3  6  5  9  6  5  9  6  9  2  5  6  4  8  4  6  2  7
#&gt; [76] 8 9 10 7 1 3 4 5 5 4 6 8 6 2 4 5 9 10 5 9 4 5 2 5 3
library(socialmixr)
library(conmat)
italy_2005 <- wpp_age("Italy", "2005")
head(italy_2005)
italy_2005_pop <- as_conmat_population(
data = italy_2005,
age = lower.age.limit,