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 / ztest.R
Created September 1, 2023 14:34
z-test
# we seek to test whether two parameters, say theta1 and theta2, are diff from each other, using a z-test
# we assume we have an estimate of the thetaj's (mle1 and mle2) and associated standard errors (se1 and se2)
# we write a function that calculate the z-statistic and return the p-value (both-sided test)
# function
ztest <- function(mle1, mle2, se1, se2){
stat <- (mle1 - mle2)/sqrt(se1^2+se2^2)
pvalue <- ifelse(stat > 0, 2 * pnorm(stat, lower.tail = FALSE), 2 * pnorm(stat, lower.tail = TRUE))
return(data.frame("z-score" = stat, "p-value" = pvalue))
}
# Cook, J. D., D. M. Williams, W. F. Porter, and S. A. Christensen. 2022.
# Improved predictions and forecasts of chronic wasting disease occurrence
# using multiple mechanism dynamic occupancy modelling.
# Journal of Wildlife Management.
# Simulation and multi-mechanism dynamic occupancy model code
#load necessary libraries
library(raster)
library(mvtnorm)
@oliviergimenez
oliviergimenez / convert_to_df.R
Created December 21, 2022 11:24
Converts MCMC output list into dataframe with better column names for plotting
# from Cole Monnahan https://github.com/colemonnahan/fcwhales
convert_to_df <- function(fit, name = NULL){
fit <- as.mcmc(fit)
post <- data.frame(do.call(rbind, fit))
new <- gsub('[.]$', '', names(post))
new <- gsub('[.]','_', new)
names(post) <- new
if(!is.null(name)) post$model <- name
return(post)
}
@oliviergimenez
oliviergimenez / finite-mixture-nimble.R
Created October 19, 2022 07:52
Finite-mixture capture-recapture models in Nimble
##--- Finite-mixture capture-recapture models
##--- O. Gimenez & D. Turek, December 2019 & October 2020
##--- Check out our paper
##--- Turek, D., C. Wehrhahn, Gimenez O. (2021). Bayesian Non-Parametric Detection Heterogeneity in Ecological Models.
##--- Environmental and Ecological Statistics 28: 355-381.
##--- PDF available here: https://arxiv.org/abs/2007.10163
##--- More on heterogeneity in capture-recapture models in
##--- https://onlinelibrary.wiley.com/doi/abs/10.1111/oik.04532
@oliviergimenez
oliviergimenez / gist:20fcdabca90eb71f50eddc23df85783a
Created July 28, 2022 11:44
occupancy models - Rota vs MacKenzie
# we get same AIC when fitting Rota model with no interaction
# vs fitting MacKenzie model to species separatately
library(unmarked)
library(mipfp)
?occuMulti
# simulate 2 species data
# https://github.com/oliviergimenez/2speciesoccupancy

Keybase proof

I hereby claim:

  • I am oliviergimenez on github.
  • I am oliviergimenez (https://keybase.io/oliviergimenez) on keybase.
  • I have a public key ASB-o-5D4dk5Z6DU4-8VoO-wp5QG9xYe5qDlKeahp3FveAo

To claim this, I am signing this object:

@oliviergimenez
oliviergimenez / generative-aRt.R
Created November 2, 2021 14:31
Generative art à la Etienne Jacob with R
# some R code to mimic animated gifs created by Etienne Jacob
# @etiennejcb
# https://bleuje.github.io/tutorials/
## load required packages
library(tidyverse)
theme_set(theme_void(base_size = 14))
library(gganimate)
##-- first tutorial https://bleuje.github.io/tutorial1/
@oliviergimenez
oliviergimenez / gist:55c8c6249c1ae582c902c8b7217c5dad
Created August 14, 2021 22:33
Create a sticker for a package (R2ucare example)
# https://zhuhao.org/post/tips-on-designing-a-hex-sticker-for-rstats-packages/
# https://github.com/GuangchuangYu/hexSticker/
library(tidyverse)
library(hexSticker)
library(png)
library(grid)
theme_set(theme_minimal())
df <- 4
@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)%>%