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 orlength(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 whichFUN
should be applied onx
. IfNULL
, 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), otherwiseNA
.- 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
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 68.11323 9
#> [2,] -7.6044815 127.98953 19
#> [3,] -5.9824582 155.84338 14
#> [4,] -4.3604350 154.02577 39
#> [5,] -2.7384117 138.55072 125
#> [6,] -1.1163884 138.29357 759
#> [7,] 0.5056349 142.46616 153
#> [8,] 2.1276582 147.30864 5
#> [9,] 3.7496815 178.57158 2
#> [10,] 5.3717047 NA 1
distroll_confidence(dat$azi.PoR, distance = dat$distance, w = 1 / dat$unc)
#> Warning: NaNs produced
#> distance x n
#> [1,] -9.2265048 147.581596 9
#> [2,] -7.6044815 44.732416 19
#> [3,] -5.9824582 101.990075 14
#> [4,] -4.3604350 43.031293 39
#> [5,] -2.7384117 9.675720 125
#> [6,] -1.1163884 4.369003 759
#> [7,] 0.5056349 11.713927 153
#> [8,] 2.1276582 20.165812 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.56974161 9
#> [2,] -7.6044815 0.31555788 19
#> [3,] -5.9824582 0.39396588 14
#> [4,] -4.3604350 0.32627346 39
#> [5,] -2.7384117 0.06582746 125
#> [6,] -1.1163884 0.09488957 759
#> [7,] 0.5056349 0.11027106 153
#> [8,] 2.1276582 0.06141144 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.19223776 9
#> [2,] -7.6044815 0.15681826 19
#> [3,] -5.9824582 0.21465546 14
#> [4,] -4.3604350 0.11958988 39
#> [5,] -2.7384117 0.02090297 125
#> [6,] -1.1163884 0.01176760 759
#> [7,] 0.5056349 0.02242678 153
#> [8,] 2.1276582 0.03415107 5
#> [9,] 3.7496815 0.05898341 2
#> [10,] 5.3717047 NA 1