This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |