Skip to content

Instantly share code, notes, and snippets.

@Pakillo
Last active March 4, 2026 09:18
Show Gist options
  • Select an option

  • Save Pakillo/926e96d715fe21fbb8ff786143776a7c to your computer and use it in GitHub Desktop.

Select an option

Save Pakillo/926e96d715fe21fbb8ff786143776a7c to your computer and use it in GitHub Desktop.
Plotless density estimation (ecology)
``` r
## Simula 200 distancias
set.seed(123)
distancias <- runif(n = 200, min = 0.1, max = 10)
mean(distancias)
#> [1] 5.11328
## Muestrea sólo 20 puntos
di <- sample(distancias, size = 20)
## Con precisión de cm
d.cm <- round(di, digits = 2)
d.cm
#> [1] 1.56 6.60 9.01 8.94 1.31 6.22 9.55 9.55 3.50 3.81 4.48 6.13 6.96 3.79 4.20
#> [16] 8.96 7.90 9.57 6.51 6.63
mean(d.cm)
#> [1] 6.259
## Con precisión de m
d.m <- round(di, digits = 0)
d.m
#> [1] 2 7 9 9 1 6 10 10 4 4 4 6 7 4 4 9 8 10 7 7
mean(d.m)
#> [1] 6.4
## Cálculo de densidades
densidad.cm <- 10000 / ((2 * mean(d.cm))^2)
densidad.cm
#> [1] 63.81608
densidad.m <- 10000 / ((2 * mean(d.m))^2)
densidad.m
#> [1] 61.03516
densidad.real <- 10000 / ((2 * mean(distancias))^2)
densidad.real
#> [1] 95.61826
```
<sup>Created on 2026-03-04 with [reprex v2.1.1](https://reprex.tidyverse.org)</sup>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment