Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In spatSample, should the default be replace = TRUE when method = "weights" ? #1565

Open
frousseu opened this issue Jul 18, 2024 · 0 comments

Comments

@frousseu
Copy link
Contributor

Hi!

When using method = "weights" in spatSample, the default replace = FALSE has the consequence that non 0 cells will be filled if the size asked is larger than the number of non 0 cells, losing the proportionality between the weights and the density of points generated. I think it would make more sense to have replace = TRUE as the default when method = "weights". In fact, I have a hard time finding a use for replace = FALSE when the weight method is used. Below is an example with the first case showing a lack of proportionality and the second case showing what I think should be the default.

Thanks!
François

library(terra)
library(sf)

set.seed(123)
r <- rast(res = 2, extent = c(0, 10, 0, 10))
v <- sample(c(0, 1, 10), ncell(r), replace = TRUE)
r <- setValues(r, v)
plot(r)

ss <- spatSample(r, size = 25, method = "weights", as.points = TRUE, replace = FALSE) |> 
  st_as_sf() |> 
  st_jitter(amount = 0.2) |> 
  st_geometry()

par(mfrow = c(1, 2))
plot(r)
plot(ss, add = TRUE)
length(ss)

ss <- spatSample(r, size = 25, method = "weights", as.points = TRUE, replace = TRUE) |> 
  st_as_sf() |> 
  st_jitter(amount = 0.2) |> 
  st_geometry()

plot(r)
plot(ss, add = TRUE)
length(ss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant