Fits a smoothing spline through a set of antigenic coordinates, and uses this to predict antigenic coordinates for all potential infection time points. It allows the user to specify "clusters" to assume that strains circulating in a given period are all identical, rather than on a continuous path through space as a function of time.

generate_antigenic_map_flexible(
  antigenic_distances,
  buckets = 1,
  clusters = NULL,
  use_clusters = FALSE,
  spar = 0.3,
  year_min = 1968,
  year_max = 2016
)

Arguments

antigenic_distances

a data frame of antigenic coordinates, with columns labelled X, Y and Strain for x coord, y coord and Strain label respectively. "Strain" should be a single number giving the year of circulation of that strain. See example_antigenic_map

buckets

the number of epochs per year. 1 means that each year has 1 strain; 12 means that each year has 12 strains (monthly resolution). Defaults to 1.

clusters

optional data frame of cluster labels, indicating which cluster each circulation year belongs to. Each row (year) is repeated by the number of buckets. Column names should be `year` and `cluster_used`.

use_clusters

if TRUE, uses the clusters data frame; otherwise, returns the usual fitted map. Defaults to FALSE.

spar

smoothing parameter passed to `smooth.spline`. Defaults to 0.3.

year_min

first year in the antigenic map. Defaults to 1968.

year_max

last year in the antigenic map. Defaults to 2016.

Value

a fitted antigenic map

Examples

if (FALSE) { # \dontrun{
antigenic_coords_path <- system.file("extdata", "fonville_map_approx.csv", package = "serosolver")
antigenic_coords <- read.csv(antigenic_coords_path, stringsAsFactors=FALSE)
antigenic_coords$Strain <- c(68,72,75,77,79,87,89,92,95,97,102,104,105,106) + 1900
antigenic_map <- generate_antigenic_map_flexible(antigenic_coords, buckets=1, year_min=1968, year_max=2015,spar=0.3)

times <- 1968:2010
n_times <- length(times)
clusters <- rep(1:5, each=10)
clusters <- clusters[1:n_times]
clusters <- data.frame(year=times, cluster_used=clusters)
antigenic_map <- generate_antigenic_map_flexible(antigenic_coords, buckets=1, 
                                                clusters=clusters,use_clusters=TRUE,
                                                year_min=1968, year_max=2010,spar=0.5)
} # }