Skip to content

Instantly share code, notes, and snippets.

View oliviergimenez's full-sized avatar
🏠
Working from home

Olivier Gimenez oliviergimenez

🏠
Working from home
View GitHub Profile
@oliviergimenez
oliviergimenez / build.yaml
Created August 3, 2021 15:04
Github action to build and deploy Hugo website
name: Build and Deploy
on:
push:
branches:
- master
jobs:
deploy:
library(tidyverse)
library(sf)
library(ggthemes)
#import des données spatiales
ContoursCommunes<-st_read("https://github.com/Valexandre/france-geojson/raw/master/communes.geojson")%>%st_transform(crs = 2154)
arr<-st_read("https://raw.githubusercontent.com/Valexandre/france-geojson/master/arrondissements-millesimes0.geojson")%>%st_transform(crs=2154)
DepsMetro<-st_read("https://raw.githubusercontent.com/Valexandre/france-geojson/master/departements.geojson")%>%
filter(nchar(code)==2)%>%
@oliviergimenez
oliviergimenez / formatQ&AfromSlack.Rmd
Created July 9, 2021 12:12
Export, clean up and tabulate questions and answers from a Slack work space with several channels into HTML tables (e.g. https://oliviergimenez.github.io/bayesian-cr-workshop/)
---
title: "Build a Q&A from Slack conversation"
author: "Olivier Gimenez"
date: "5/19/2021, 9/7/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
```
@oliviergimenez
oliviergimenez / mcmc_betabinomial.R
Last active January 15, 2026 14:28
Visualise Metropolis algorithm with binomial likelihood and beta prior
# load packages
library(tidyverse)
theme_set(theme_light(base_size = 16))
library(gganimate)
library(magick)
# deer data, 19 "success" out of 57 "attempts"
survived <- 19
released <- 57
@oliviergimenez
oliviergimenez / perseverance.R
Created February 24, 2021 00:04
Decoding the hidden message in Perseverance parachute with R
library(tidyverse)
options(warn = -1) # suppress warnings
# read in the rings as character strings
ring <- data.frame(inner_ring = "00000001000000000001000001001000000001010001111111111111111111111111111111111111",
middle_ring_first = "00000011010000001001000000011100000010000000010100000001100100011111111111111111",
middle_ring_second = "00000101000000001000000000100100000011100000000111000001001100011111111111111111")
end <- seq(10, 80, by = 10) # create vector of upper bound for each chunk of 10 bits
@oliviergimenez
oliviergimenez / kuomallick.R
Created February 16, 2021 10:04
Bayesian variable selection à la Kuo & Mallick w/ Jags
# je suis parti de ce post
# https://darrenjw.wordpress.com/2012/11/20/getting-started-with-bayesian-variable-selection-using-jags-and-rjags/
# je n ai utilise que le code de la section "Basic variable selection" c'est a dire que
# j ai laisse tombé les modifs sur le code que l'auteur propose dans les sections
# "Variable selection with random effects" et "Variable selection with random effects and a prior on the inclusion probability"
# j ai rajoute des lignes de code a la fin pour calculer les probabilites a posteriori des modeles
# (voir par exemple la table 2 dans https://dl.dropboxusercontent.com/u/23160641/my-pubs/Gimenezetal2009Evolution.pdf)
@oliviergimenez
oliviergimenez / Conway-Game-of-Life-R.R
Created December 29, 2020 19:02
various R implementations of Conway's Game of Life
#------- inspiration: https://www.nytimes.com/2020/12/28/science/math-conway-game-of-life.html
#------- see also https://medium.com/tebs-lab/optimizing-conways-game-of-life-12f1b7f2f54c
#---- implementation 1
install.packages("fun")
library(fun)
demo("GameOfLife")
#---- implementation 2 (https://www.r-bloggers.com/2012/11/fast-conways-game-of-life-in-r/)
@oliviergimenez
oliviergimenez / grouped_lasso.R
Created December 29, 2020 08:41
Grouped lasso with both discrete/continuous predictors and normal/non-normal response
# illustrates grouped lasso with simulations
# with normal and non-normal responses
# and a mix and discrete/continuous predictors
#----- normal response
library(gglasso)
create_factor <- function(nb_lvl, n = 100 ){
factor(sample(letters[1:nb_lvl],n, replace = TRUE))}
@oliviergimenez
oliviergimenez / dipper.csv
Created December 3, 2020 04:41
Use Nimble to generate inits for latent states
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
h1;h2;h3;h4;h5;h6;h7;males;females
1;1;1;1;1;1;0;1;0
1;1;1;1;1;0;0;0;1
1;1;1;1;0;0;0;1;0
1;1;1;1;0;0;0;0;1
1;1;0;1;1;1;0;0;1
1;1;0;0;0;0;0;1;0
1;1;0;0;0;0;0;1;0
1;1;0;0;0;0;0;1;0
1;1;0;0;0;0;0;1;0
@oliviergimenez
oliviergimenez / lifedead_og.R
Created November 26, 2020 09:13
Fit model combining live recapture and dead recoveries in Jags using SSM formulation of multistate models
# Fit model combining live recapture and dead recoveries in Jags using SSM formulation of multistate models
# Warning: if initial values are generated from the ld.init() function, we failed at recovering the values
# used to simulate the data; everything goes well if we use the true latent states (data are simulated) as initial values
# Define function to simulate multistate capture-recapture data
simul.ms <- function(PSI.STATE, PSI.OBS, marked, unobservable = NA){
# Unobservable: number of state that is unobservable
n.occasions <- dim(PSI.STATE)[4] + 1
CH <- CH.TRUE <- matrix(NA, ncol = n.occasions, nrow = sum(marked))
# Define a vector with the occasion of marking