Skip to content

Instantly share code, notes, and snippets.

View BrentPease1's full-sized avatar

Brent Pease BrentPease1

View GitHub Profile
@Pakillo
Pakillo / relief_maps_rspatial.R
Last active July 22, 2022 15:59
Quick elevation maps with R
library(sf)
library(terra)
## Define area
coords <- data.frame(x = c(-5.5, -5.5, -5.3, -5.3),
y = c(36.7, 36.8, 36.7, 36.8))
coords.sf <- st_as_sf(coords, coords = c("x", "y"), crs = 4326)
## Download elevation data
@scbrown86
scbrown86 / gisfrag.R
Last active July 29, 2020 23:16
GISFrag metric
## GISFrag metric
## https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19950017676.pdf
## 1) Produce a proximity (distance) map between 'patches'
## 2) GISFrag == mean of all values on the proximity map
## 3) Large GISFrag values reflect low forest fragmentation, low values == high fragmentation
gisFrag <- function(x, ...) {
## x needs to be a raster where cells with suitable habitat are coded as 1
## unsuitable cells coded with 0
## extract cell numbers for suitable cells
@famuvie
famuvie / multilevel_inla_lmer_stan.R
Created December 12, 2017 15:50
Multilevel models with lme4 and INLA (and Stan)
# Comparison estimations of multi-level models between lme4 and INLA
# inspired by question in the r-inla group:
# https://groups.google.com/forum/#!topic/r-inla-discussion-group/tmNdcYQ6KHk
pacman::p_load(INLA, lme4, tidyverse, broom, GGally)
sleepstudy %>%
ggplot(aes(Days, Reaction, color = Subject)) +
geom_point()
@florianhartig
florianhartig / gaussianAutoregressiveExample.jags.
Last active November 9, 2021 11:07
A modification of code posted originally by Petr Keil http://www.petrkeil.com/?p=1910, to illustrate some comments I made in response to this blog post
library(mvtnorm) # to draw multivariate normal outcomes
library(R2jags) # JAGS-R interface
# function that makes distance matrix for a side*side 2D array
dist.matrix <- function(side)
{
row.coords <- rep(1:side, times=side)
col.coords <- rep(1:side, each=side)
row.col <- data.frame(row.coords, col.coords)
D <- dist(row.col, method="euclidean", diag=TRUE, upper=TRUE)