kernel.smooth.in.time | R Documentation |
This function performs kernel smoothing on a dataset in time alone.
kernel.smooth.in.time( dataset, dependent.variable = "dependent.variable", time = "year", weight = "weight", bandwidth = 10, sample.density.threshold = 3, length.out = 1000, alpha = 0.05, xlabel = "year", ylabel, greyscale = "compatible", save.path = "", measure.times, kernel.function = gaussian.kernel )
dataset |
The dataset to be smoothed as a data.frame. |
dependent.variable |
String name of the column in dataset with the dependent variable (defaults to "dependent.variable"); this column should be numeric or factor. |
time |
String name of the column in dataset with the time variable (defaults to "year"). |
weight |
String name of column in the dataset with numeric weights (defaults to "weight"). |
bandwidth |
Numeric bandwidth of the kernel function. |
sample.density.threshold |
Numeric local density of samples below which no estimates will be returned. |
length.out |
The number of measure points along the time axis (defaults to 1000). |
alpha |
Numeric alpha for calculating error margins (defaults to 0.05). |
xlabel |
String label for the x-axis in returned plot (defaults to "year"). |
ylabel |
String label for the y-axis in returned plot. |
greyscale |
If TRUE, plot will be in greyscale; if "compatible", plot will use a colour spectrum which also goes light>dark; otherwise, will use a non-greyscale-compatible colour scale. |
save.path |
String path to save plot to (if not given, plot will not be saved). |
measure.times |
A numeric vector of specific times at which to make estimates; if given, sample.density.threshold and length.out will be ignored. |
kernel.function |
The kernel function, one of gaussian.kernel, gaussian.square.kernel, triangular.kernel, square.kernel, or a custom function. |
A list containing a data.frame with the smoothed estimates, and a ggplot grob visualising them.
n=1000; synthesised.data<-data.frame(x=stats::runif(n),y=stats::runif(n), year=stats::runif(n,0,sqrt(2))); synthesised.data$dependent.variable<-unlist(lapply(1:nrow(synthesised.data), function(X){ stats::dist(as.matrix(synthesised.data[c(1,X),1:2]),method = "euclidean")<synthesised.data$year[X]; })) result<-kernelPhil::kernel.smooth.in.time(dataset = synthesised.data, bandwidth = 0.05,sample.density.threshold = 100); result$plot;