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
library(terra)
#> terra 1.7.78

We are exploring an approach in {geotargets} for splitting up a raster into tiles and then using that to split up rasters that we will then do tasks on. To do this, Eric wrote this create_tile_exts function, which is powered by terra::getTileExtents:

# Set-up ---------
library(conmat)
library(tidyverse)
library(gratia)
library(patchwork)
set.seed(2022 - 12 - 19)
# Obtain data from conmat ----------
---
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,