MyNixOS website logo
Description

Polygons of Bivariate Density Distributions.

With bivariate data, it is possible to calculate 2-dimensional kernel density estimates that return polygons at given levels of probability. 'densityarea' returns these polygons for analysis, including for calculating their area.

densityarea densityarea website

R-CMD-check

The package {ggdensity}[^1] allows for plotting interpretable bivariate densities by using highest density ranges (HDRs). For example:

library(tibble)
library(ggplot2)
library(ggdensity)

set.seed(10)
df <- tibble(
  x = c(rnorm(100), rnorm(100, mean = 3)),
  y = c(rnorm(100), rnorm(100, mean = 3))
)

ggplot(df, aes(x,y))+
  stat_hdr()

{densityarea} gives direct access to these HDRs, either as data frames or as simple features, for further analysis.

Installation

You can install {densityarea} from CRAN with:

install.packages("densityarea")

Or you can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("JoFrhwld/densityarea")

Example

The use case the package was initially developed for was for estimating vowel space areas.

library(densityarea)
library(dplyr)
library(tidyr)
library(sf)

data(s01)

# initial data processing

s01 |> 
  mutate(lF1 = -log(F1),
         lF2 = -log(F2))->
  s01

To get this speaker’s vowel space area we can pass the data through dplyr::reframe()

s01 |> 
  reframe(
    density_area(lF2, lF1, probs = 0.8)
  )
#> # A tibble: 1 × 3
#>   level_id  prob  area
#>      <int> <dbl> <dbl>
#> 1        1   0.8 0.406

Or, we could get the spatial polygon associated with the 80% probability level

s01 |> 
  reframe(
    density_polygons(lF2, lF1, probs = 0.8, as_sf = T)
  )
#> # A tibble: 1 × 3
#>   level_id  prob                                                        geometry
#>      <int> <dbl>                                                       <POLYGON>
#> 1        1   0.8 ((-7.777586 -6.009484, -7.801131 -6.010429, -7.824676 -6.01700…

For more

For more details on using {densityarea}, see , and for further information on using spatial polygons, see vignette("sf-operations").

[^1]: Otto J, Kahle D (2023). ggdensity: Interpretable Bivariate Density Visualization with ‘ggplot2’. <https://github.com/jamesotto852/ggdensity/

Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows