assemble_ts | R Documentation |
This function assembles a basic dataframe structure that defines, for each factor level (i.e., individual) inputted, a sequence of time steps, possibly differing in duration and resolution across factor levels. Since this function was inspired by the simulation of depth time series, commonly assumed drivers of depth (namely, sex, length, sun angle, lunar phase and Julian day) can be included in the dataframe by supplying these to the covariates
argument. In this case, sex is simulated for each individual from a discrete distribution with a user-defined parameter (the probability of sampling a female) and length is simulated for each individual from a Gamma distribution with user-specified parameters. Sun angle, lunar phase and Julian day are calculated for each time stamp using getSunlightPosition
, lunar.phase
and yday
respectively. For other covariates/ecological time series, the user can use this dataframe to define covariate values. In both cases, this information can then be used simulate values of a response (see sim_ts
).
assemble_ts( start_date, start_date_variable = TRUE, max_duration_days, duration_days_variable = FALSE, resolution_minutes, n_individuals, longitude, latitude, tz = "UTC", covariates = NULL, parameters = list(start_date = list(ndays = max_duration_days - 1, prob = NULL, replace = TRUE), duration_days = list(prob = NULL, replace = TRUE), resolution_mins = list(prob = NULL, replace = TRUE), sex = list(Pf = 0.5, replace = TRUE), length = list(shape = 25, scale = 4, plot_density_curve = TRUE)) )
start_date |
A character specifying the date of the first observation, specified as "yyyy-mm-dd". |
start_date_variable |
A logical input specifying whether or not the start date for simulated time series should differ among individuals (if multiple individuals are specified). This is controlled via the |
max_duration_days |
A number specifying the maximum duration, in days, over which to simulate data. |
duration_days_variable |
A logical input specifying whether or not the duration of time series for each factor level should vary (if multiple levels have been specified). |
resolution_minutes |
A number or vector specifying the duration, in minutes, between consecutive simulated time stamps. If a single number is specified, the resolution is taken to be the same across all individuals. If more than one number is defined, supplied numbers are taken to be the resolutions at which individual time series will be sampled. The duration between consecutive simulated time stamps for each individual is sampled randomly from this vector, according to the specifications in the |
n_individuals |
A number specifying the number of individuals (factor levels) for which to simulate data. |
longitude |
A number specifying the longitude (decimal degrees) of the simulated location. This is required to calculate the covariate |
latitude |
A number specifying the latitude (decimal degrees) of the simulated location. This is required to calculate the covariate |
tz |
A character specifying the time zone. The default is |
covariates |
A character vector specifying the covariates to be included in the dataframe. Currently supported covariates are: (1) |
parameters |
A nested list specifying additional parameters. This currently supports the following elements. (1) An element which adjusts the variation in |
A dataframe comprising a sequence of time stamps (as possible covariate values) is simulated in order to set up a dataframe which can be used to simulate values of a response. sim_ts
provides a starting framework to simulate the response.
The function outputs a dataframe, with the following columns: (1) 'individual', an integer which distinguishes each unique individual; (2) 'timestamp', a time in POSIXct format, which defines each unique observation/time step, at the specified resolution, (3) 'hourofday', an integer which defines the hour of day; and (4) columns for each of the inputted covariates (if applicable).
GammaDist
, sample
, sim_ts
# Simulate a dataframe for a single individual: assemble_ts(start_date = "2017-01-01", start_date_variable = FALSE, max_duration_days = 10, duration_days_variable = FALSE, resolution_minutes = 720, n_individuals = 1, longitude = 5, latitude = 65, tz = "UTC", covariates = c("sex", "length", "sun_angle", "lunar_phase", "julian_day"), parameters = list( sex = list(Pf = 0.5, replace = TRUE), length = list(shape = 10, scale = 4, plot_density_curve = TRUE) ) ) # Simulate data from multiple individuals with variable # .. start dates, durations and resolutions assemble_ts(start_date = "2018-01-01", start_date_variable = TRUE, max_duration_days = 21, duration_days_variable = TRUE, resolution_minutes = c(2, 30, 60), n_individuals = 3, longitude = 5, latitude = 65, tz = "UTC", covariates = c("sex", "length", "sun_angle", "lunar_phase", "julian_day"), parameters = list(start_date = list(ndays = 100, prob = NULL, replace = TRUE), duration_days = list(prob = NULL, replace = TRUE), resolution_mins = list(prob = NULL, replace = TRUE), sex = list(Pf = 0.5, replace = TRUE), length = list(shape = 10, scale = 4, plot_density_curve = TRUE) ) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.