closest.pt: Determine Closest Point

View source: R/Francis_bomb_functions.R

closest.ptR Documentation

Determine Closest Point

Description

closest.pt finds, for each sample point in samp, the point on the reference curve (continuous linear spline defined by ref) that is 'closest' to it. Distance (and thus the definition of 'closest') is defined, differently for each sample point, by dividing the x and y values by the sampling errors for that point.

Usage

closest.pt(
  ref,
  samp,
  ref.x = "x",
  ref.y = "y",
  samp.x = "Sample.Year",
  samp.y = "F14C",
  age.err = "SE.Age",
  y.err = "F14C.SD",
  plotit = FALSE,
  incl.dist = FALSE
)

Arguments

ref

list, data frame, or matrix containing x- and y-coordinates for a reference line one wishes to compare sample points to. Typically this will be the output from a call to get.ref.line.

samp

data frame, with a minimum of 4 columns, representing your 'test' data set. Individual columns should represent x-cordinates, y-cordinates, aging error, and y error. Typically x will represnt sample year or birth year and y will rerpresent either D14C or F14C.

ref.x

character string giving the name of the x-value in the provided ref data set.

ref.y

character string giving the name of the y-value in the provided ref data set.

samp.x

character string giving the name of the x-value in the provided samp data set.

samp.y

character string giving the name of the y-value in the provided samp data set.

age.err

character string giving the name of the column representing aging error provided in the samp data set.

y.err

character string giving the name of the column representing the y-variable error provided in the samp data set.

plotit

logical indicating whether to generate plot

incl.dist

logical indicating whether to include distance calculations in resultant output

Value

A dataframe with components (each with length nrow(samp)) with components X, Y - x & y coordinates of closest points - and optionally (if incl.dist = TRUE) dist - signed distance from reference curve. Optionally plots (if plot = TRUE) the data, including lines joining each sample point to its closest point.

See Also

Other Bomb Radiocarbon Analyses: bias.plot.BR(), calc.bias(), calc.h(), get.h.from.bias(), get.nearest(), get.ref.line(), sim.hdist()

Examples

data(snapper)
snapper.red <- snapper[snapper$C14year >= 1955 & snapper$C14year <= 1972, ]
data(bluenose)
bluenose.red <- bluenose[bluenose$C14year >= 1955 &
  bluenose$C14year <= 1972, ]
bluenose.red <- bluenose.red[bluenose.red$C14 >= -506 &
  bluenose.red$C14 <= 94.0, ]
ref <- get.ref.line(snapper.red$C14year, snapper.red$C14)
closest.pt(ref = ref, samp = bluenose.red, samp.x = "C14year",
  samp.y = "C14", age.err = "age.err", y.err = "C14.err", plot = TRUE,
  incl.dist = TRUE)

ballengerj/FishyR documentation built on June 17, 2022, 10:33 p.m.