cleanup_times: Cleaning up data

Description Usage Arguments Details Value Examples

View source: R/cleanup.R

Description

Cleanup times in population data frame, so that they are regularly spaced and stop at the correct time, using either means to interpolate new data points or previous value for events. We assume when the data frame stops before end.time that the state then remaining unchanged.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
cleanup_times(
  populations,
  are.events,
  timestep = 1,
  end.time = max(populations$time),
  times = seq(from = min(populations$time), to = end.time, by = timestep)
)

cleanup_events(populations, ...)

cleanup_timesteps(populations, ...)

Arguments

populations

- a data frame with columns corresponding to different population segments and a 'time' column

are.events

- whether the times in the data frame are events (therefore should take last event to determine state) or not (therefore interpolate)

timestep

- (optionally) timestep required for times - default 1

end.time

- (optionally) end of simulation time required - default max(populations$time)

times

- (optionally) vector of times to be reproduced - default seq(from=min(populations$time), to=end.time, by=timestep)

...

- pass through arguments for cleanup_events() and cleanup_timesteps() to cleanup_times()

Details

cleanup_events() cleans up times of an event-based population data frame, cleanup_timesteps() cleans up times of an timestep-based population data frame.

Value

Revised data frame with correct timings

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
growth <- function(latest.df, growth.rate) {
current.count <- latest.df$count
growth.num <- current.count * growth.rate
next.count <- current.count + growth.num
next.time <- latest.df$time + 1
new.df <- data.frame(time=next.time, count=next.count)
finished <- next.count == 0
list(updated.pop=new.df, end.experiment=finished)
}
df <- data.frame(time=0, count=1)
results <- run_simulation(growth, df, 100, growth.rate=0.1)
plot_populations(results)
short.results <- cleanup_timesteps(results, timestep=20, end.time=80)
plot_populations(short.results, new.graph=FALSE, lty=2)

boydorr/ProgInR documentation built on Nov. 16, 2019, 3:34 a.m.