Skip to content

Instantly share code, notes, and snippets.

View njtierney's full-sized avatar
👷‍♂️
Have some work availability from October

Nicholas Tierney njtierney

👷‍♂️
Have some work availability from October
View GitHub Profile
people <- c("ousmane", "sylviane", "victoire")
indices <- c(1,1,1,2,2,3,3,3,3)

repeated_people <- people[indices]

# how to count these people?
table(repeated_people)
#> repeated_people
#>  ousmane sylviane victoire 
@njtierney
njtierney / randomised-quantile-residuials.md
Last active February 27, 2025 03:33
Randomised quantile residuials
n <- 1000
x <- sort(rnorm(n))
alpha <- -1
beta <- 0.3
obs_sd <- 1.2
y <- rnorm(n, alpha + beta * x, obs_sd)


library(greta)
library(tidyverse)
# example structure of the data
# some of the columns are:
# Months (1 2 3, 13, 14 15), Arm (control, intervention)
# Before_After (beofre, after), Village ( 1:8), household (1:8), weight (number?)
# this is painful...
tibble(
month = c(1, 1, 2, 2, 3, 3, 13, 13, 14, 14, 15, 15),
library(tidyverse)

# building the bones of the data
# Specify the ranges of each of the data
# 
household_design <- expand_grid(
  month = c(1,2,3, 13, 14, 15),
  arm = c("C", "I"),
  b_a = c("b", "a"),
library(tidyverse)
# example lagging code
n <- 100

grid_cov <- expand_grid(
  covariates = c("rainfall", "temperature"),
  years = 2000:2022,
  row = seq_len(n)
) |>
@njtierney
njtierney / year-lag.md
Created November 14, 2024 03:06
exploring creating year lag
# example lagging code
library(tidyverse)

n <- 100

grid_cov <- expand_grid(
  covariates = c("rainfall", "temperature"),
  years = 2000:2022,
  row = seq_len(n)
elev <-  terra::rast(system.file("ex", "elev.tif", package = "terra"))
elev
#> class       : SpatRaster 
#> dimensions  : 90, 95, 1  (nrow, ncol, nlyr)
#> resolution  : 0.008333333, 0.008333333  (x, y)
#> extent      : 5.741667, 6.533333, 49.44167, 50.19167  (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326) 
#> source      : elev.tif 
#> name        : elevation 
@njtierney
njtierney / compare-git-commits.R
Created October 30, 2024 06:52
Helper for comparing git commits
compare_git_commits <- function(repo, sha1, sha2){
# https://github.com/github-linguist/linguist/compare/f75c570..3391dcc
glue::glue("{repo}/compare/{sha1}..{sha2}")
}
compare_greta_commits <- function(sha1, sha2){
compare_git_commits(repo = "https://github.com/greta-dev/greta/",
sha1 = sha1,
sha2 = sha2)
}
library(distributional)
library(tidyverse)
tibble(
  dist = c(dist_normal(0,1), dist_normal(4,7), dist_normal(2,8))
) |> 
  mutate(
    sample = generate(dist, 10),
    params = parameters(dist)
  )
# General process would be:
# 1. Simulate a wishart draw x with rWish()
# 2. Transform x to the equivalent free_state, using the bijector but running it in reverse
# 3. Run the log_prob() function on free_state
# 4. Run dWish(..., log = TRUE) on x, and compare with result of step 3
devtools::load_all(".")
#> ℹ Loading greta
#> ℹ Initialising python and checking dependencies, this may take a moment.
#>