Skip to contents

A generic function for applying a function to rolling margins of an array along an additional value.

Usage

distroll_circstats(
  x,
  distance,
  FUN,
  width = NULL,
  min_n = 2,
  align = c("right", "center", "left"),
  w = NULL,
  sort = TRUE,
  ...
)

distroll_confidence(
  x,
  distance,
  w = NULL,
  width = NULL,
  min_n = 2,
  align = c("right", "center", "left"),
  sort = TRUE,
  ...
)

distroll_dispersion(
  x,
  y,
  w = NULL,
  w.y = NULL,
  distance,
  width = NULL,
  min_n = 2,
  align = c("right", "center", "left"),
  sort = TRUE,
  ...
)

distroll_dispersion_sde(
  x,
  y,
  w = NULL,
  w.y = NULL,
  distance,
  width = NULL,
  min_n = 2,
  align = c("right", "center", "left"),
  sort = TRUE,
  ...
)

Arguments

x, y

vectors of numeric values in degrees. length(y) is either 1 or length(x)

distance

numeric. the independent variable along the values in x are sorted, e.g. the plate boundary distances

FUN

the function to be applied

width

numeric. the range across distance on which FUN should be applied on x. If NULL, then width is a number that separates the distances in 10 equal groups.

min_n

integer. The minimum values that should be considered in FUN (2 by default), otherwise NA.

align

specifies whether the index of the result should be left- or right-aligned or centered (default) compared to the rolling window of observations. This argument is only used if width represents widths.

w

numeric. the weighting for x

sort

logical. Should the values be sorted after distance prior to applying the function (TRUE by default).

...

optional arguments to FUN

w.y

numeric. the weighting for y

Value

two-column vectors of (sorted) x and the rolled statistics along distance.

Examples

data("plates")
plate_boundary <- subset(plates, plates$pair == "na-pa")
data("san_andreas")
PoR <- subset(nuvel1, nuvel1$plate.rot == "na")
san_andreas$distance <- distance_from_pb(
  x = san_andreas,
  PoR = PoR,
  pb = plate_boundary,
  tangential = TRUE
)
dat <- san_andreas |> cbind(PoR_shmax(san_andreas, PoR, "right"))

distroll_circstats(dat$azi.PoR, distance = dat$distance, w = 1 / dat$unc, FUN = circular_mean)
#>         distance         x   n
#>  [1,] -9.2265048  65.71825   7
#>  [2,] -7.6044815 127.98953  19
#>  [3,] -5.9824582 155.84338  14
#>  [4,] -4.3604350 154.03429  39
#>  [5,] -2.7384117 138.51693 118
#>  [6,] -1.1163884 138.28289 746
#>  [7,]  0.5056349 142.57999 131
#>  [8,]  2.1276582 147.38000   5
#>  [9,]  3.7496815 178.57158   2
#> [10,]  5.3717047        NA   1
distroll_confidence(dat$azi.PoR, distance = dat$distance, w = 1 / dat$unc)
#>         distance          x   n
#>  [1,] -9.2265048  27.363250   7
#>  [2,] -7.6044815  96.659444  19
#>  [3,] -5.9824582  36.324307  14
#>  [4,] -4.3604350 103.822045  39
#>  [5,] -2.7384117  11.754109 118
#>  [6,] -1.1163884   5.421959 746
#>  [7,]  0.5056349  16.430045 131
#>  [8,]  2.1276582  34.620399   5
#>  [9,]  3.7496815        NaN   2
#> [10,]  5.3717047         NA   1
distroll_dispersion(dat$azi.PoR, y = 135, distance = dat$distance, w = 1 / dat$unc)
#>         distance          x   n
#>  [1,] -9.2265048 0.55904215   7
#>  [2,] -7.6044815 0.31555788  19
#>  [3,] -5.9824582 0.39396588  14
#>  [4,] -4.3604350 0.32629112  39
#>  [5,] -2.7384117 0.06532730 118
#>  [6,] -1.1163884 0.09484305 746
#>  [7,]  0.5056349 0.11027953 131
#>  [8,]  2.1276582 0.06254410   5
#>  [9,]  3.7496815 0.47800478   2
#> [10,]  5.3717047         NA   1
distroll_dispersion_sde(dat$azi.PoR, y = 135, distance = dat$distance, w = 1 / dat$unc, R = 100)
#>         distance          x   n
#>  [1,] -9.2265048 0.21314562   7
#>  [2,] -7.6044815 0.14197062  19
#>  [3,] -5.9824582 0.22068858  14
#>  [4,] -4.3604350 0.12652655  39
#>  [5,] -2.7384117 0.02049644 118
#>  [6,] -1.1163884 0.01181868 746
#>  [7,]  0.5056349 0.02982692 131
#>  [8,]  2.1276582 0.03516382   5
#>  [9,]  3.7496815 0.05893620   2
#> [10,]  5.3717047         NA   1