A generic function for applying a function to rolling margins of an array along an additional value.
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
Returns
two-column vectors of (sorted) x and the rolled statistics along distance.
Note
distroll_circstats() and friends are complete, and for new code it is recommended switching to distance_binned_stats(), which is fasrter, easier to use, more featureful, and still under active development.
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
)|> head()distroll_confidence(dat$azi.PoR, distance = dat$distance, w =1/ dat$unc)|> head()distroll_dispersion(dat$azi.PoR, y =135, distance = dat$distance, w =1/ dat$unc
)|> head()distroll_dispersion_sde(dat$azi.PoR, y =135, distance = dat$distance, w =1/ dat$unc, R =100)|> head()# New functionsdistance_binned_stats( dat$azi.PoR, distance = dat$distance, width.breaks =1, unc = dat$unc, prd =135)|> head()