Takes the output of aggregateSimulation, and interpolates it into a regular time grid.

toRegularTime(
  x = NULL,
  time.column = "Time",
  interpolation.interval = NULL,
  columns.to.interpolate = c("Suitability",
                             "Driver.A",
                             "Pollen")
  )

Arguments

x

list of dataframes (generally the output of aggregateSimulation) or single dataframe with irregular time series.

time.column

character string, default value is "Time".

interpolation.interval

integer, in years, time length encompassed by each sample.

columns.to.interpolate

character string or character vector, columns of simulation output to be interpolated. Any subset of: "Pollen", "Population.mature", "Population.immature", "Population.viable.seeds", "Suitability", "Biomass.total", "Biomass.mature", "Biomass.immature", "Mortality.mature", "Mortality.immature", "Driver.A", "Driver.B".

Value

If x is a list of dataframes, the function returns a list with the same structure as the input list. If x is a dataframe, the function returns a dataframe. In any case, output dataframes have the columns "Time" (now regular), and any column listed in columns.to.interpolate. Important: as in the input data, the time column of the output data has lower time for oldest samples and higher time for newest samples.

Details

This function fits a loess model of the form y ~ x, where y is any column given by columns.to.interpolate and x is the column given by the time.column argument. The model is used to interpolate column y on a regular time series of intervals equal to interpolation.interval. If x is a matrix-like list returned by aggregateSimulation (on results of simulateAccumulationRate and simulatePopulation), the first column of the matrix will already have a regular time column, and therefore nothing will be done with this column of the list.

See also

Examples

# NOT RUN { #getting example data data(simulation) data(accumulationRate) #aggregating first simulation outcome sim.output.aggregated <- aggregateSimulation( simulation.output = simulation[1], accumulation.rate = accumulationRate, sampling.intervals = c(2,6)) #to regular time sim.output.aggregated <- toRegularTime( x=sim.output.aggregated, time.column ="Time", interpolation.interval = 10, columns.to.interpolate = c("Suitability", "Pollen") ) #comparing simulations par(mfrow = c(3,1)) #notice the subsetting of the given column of the input list plot(sim.output.aggregated[[1,1]]$Time, sim.output.aggregated[[1,1]]$Pollen, type = "l", xlim = c(500, 1000), main = "Annual" ) plot(sim.output.aggregated[[1,2]]$Time, sim.output.aggregated[[1,2]]$Pollen, type = "l", xlim = c(500, 1000), main = "2cm" ) plot(sim.output.aggregated[[1,3]]$Time, sim.output.aggregated[[1,3]]$Pollen, type = "l", xlim = c(500, 1000), main = "6cm" ) #check differences in nrow nrow(sim.output.aggregated[[1,1]]) #original data nrow(sim.output.aggregated[[1,2]]) #2cm nrow(sim.output.aggregated[[1,3]]) #6cm intervals # }