Skip to content

Instantly share code, notes, and snippets.

@benmarwick
Created October 11, 2022 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benmarwick/fb2ec2ddfcc3947a4e478999b166a80c to your computer and use it in GitHub Desktop.
Save benmarwick/fb2ec2ddfcc3947a4e478999b166a80c to your computer and use it in GitHub Desktop.
---
title: "Untitled"
format: html
editor: visual
---
## Introduction
The aim of this report ...
Q1.
Q2.
Q3.
```{r}
library(tidyverse)
library(here)
library(sf)
library(terra) # was raster
library(spatstat)
library(maptools)
unzip("data.zip", exdir = "data")
# read in the spatial data files
survey_area <-
st_read(here("data/survey_area/survey_area.shp"))
ahu <-
st_read(here("data/ahu/ahu.shp"))
water <-
st_read(here("data/water/water.shp"))
rock_mulch <-
rast(here("data/mulch/mulch.tif"))
# prepare inline code
how_many_ahu <- nrow(ahu)
```
... `r how_many_ahu`
The data come from DiNapoli et al. (2019)
## Exploratory data visualation
```{r}
#| label: fig-overview-map
#| fig-cap: "change me!"
# convert raster to df to use with ggplot
rock_mulch_df <-
as.data.frame(rock_mulch, xy = TRUE)
ggplot() +
geom_sf(data = survey_area) +
geom_raster(data = rock_mulch_df,
aes(x = x,
y = y,
fill = mulch)) +
geom_sf(data = ahu,
colour = "red",
shape = 15) +
geom_sf(data = water,
colour = "grey") +
theme_minimal()
```
In @fig-overview-map we can see...
```{r}
# convert data to use with spatstat functions
survey_win <-
as.owin(survey_area)
ahu_pp <- ppp(ahu$POINT_X,
ahu$POINT_Y,
window = survey_win)
water_pp <- ppp(water$POINT_X,
water$POINT_Y,
window = survey_win)
water_pp <- unique(water_pp)
# create distances map for water
water_dist <- distmap(water_pp)
# create distance map for lithic mulch
mulch_dist <- as.im(rock_mulch_df)
```
## Hypothesis testing
```{r}
#| label: fig-hyp-testing
#| fig-cap: "change me!"
#| fig-subcap:
#| - "Water"
#| - "Mulch"
#| layout-ncol: 2
# freshwater
ahu_water_cdf <- cdf.test(ahu_pp,
water_dist,
alternative = "greater")
ahu_water_cdf_pval <-
round(ahu_water_cdf$p.value, 4)
plot(ahu_water_cdf,
style = "cdf",
ylab = "Probability",
xlab = "Distance to freshwater")
# lithic mulch gardens
ahu_mulch_cdf <-
cdf.test(ahu_pp,
mulch_dist,
alternative = "greater")
ahu_mulch_cdf_pval <-
round(ahu_mulch_cdf$p.value, 4)
plot(ahu_mulch_cdf,
style = "cdf",
ylab = "Probability",
xlab = "Distance to Rock Mulch")
```
In @fig-hyp-testing we can see ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment