Skip to contents

Useful for development or generating easily reproducible examples

Usage

generate_random_ts(
  n = 1,
  lengths = 36,
  starts = 1988,
  frequencies = 12,
  ranges_min = -1,
  ranges_max = 1,
  shifts = 0,
  ts_names = sprintf("ts%d", 1:n),
  seed = 30042018,
  random_NAs = FALSE,
  random_NA_proportions = 0.1,
  normally_distributed = FALSE,
  normal_means = 0,
  normal_sds = 1,
  frequency_shifts = FALSE,
  frequency_shift_after = 0.5
)

Arguments

n

The number of ts objects to generate

lengths

The lengths of the time series

starts

The start points of the time series in single number notation (e.g. 1990.5)

frequencies

The frequencies of the time series

ranges_min

The minimum values of the time series (if normally_distributed == FALSE)

ranges_max

The maximum values of the time series (if normally_distributed == FALSE)

shifts

The shifts of time series values per series

ts_names

The names of the ts objects in the resulting list

seed

The random seed to be used

random_NAs

Whether or not to introcude NA values at random positions in the ts

random_NA_proportions

The fraction of values to be replaced with NAs if random_NAs is TRUE for the series

normally_distributed

Use normal distribution instead of uniform

normal_means

The means to use for normal distribution. Ignored unless normally_distributed is set to TRUE.

normal_sds

The sds to use for normal distribution. Ignored unless normally_distributed is set to TRUE.

frequency_shifts

Introduce frequency shifts (from 4 to 12) in the ts

frequency_shift_after

After what fraction of the ts to shift frequencies

Value

A list of ts objects

Details

Except for n and ts_names, all parameters accept either a single value or a vector of values. If a single value is supplied, that value is used for all time series being generated. If a vector is supplied, its values will be used for the corresponding series (e.g. starts[1] is used for the first series, starts[2] for the second and so on). Vectors are recycled if n is larger than their length.

If a ts_names vector is supplied, it must have length n and must not contain duplicates.

Examples

generate_random_ts()
#> $ts1
#>               Jan          Feb          Mar          Apr          May
#> 1988  0.893485502 -0.688892365 -0.229749839 -0.922924874  0.124839254
#> 1989  0.967893334 -0.594695907  0.322527747  0.496914903  0.727370868
#> 1990  0.804336180 -0.842539105  0.546138290  0.177073403  0.396821795
#>               Jun          Jul          Aug          Sep          Oct
#> 1988 -0.120733925 -0.624176192  0.020836985 -0.608169273 -0.298081449
#> 1989  0.758888437 -0.744613007  0.377339070 -0.925579273 -0.484392250
#> 1990  0.684014794  0.912440008 -0.040721069 -0.003143072  0.942819356
#>               Nov          Dec
#> 1988 -0.189186306  0.227694534
#> 1989  0.989371605  0.172056411
#> 1990  0.666346054  0.357420872
#> 

generate_random_ts(n = 3, ranges_min = c(-10, 0, 10), ranges_max = 20, starts = 2011)
#> $ts1
#>             Jan        Feb        Mar        Apr        May        Jun
#> 2011 18.4022825 -5.3333855  1.5537524 -8.8438731  6.8725888  3.1889911
#> 2012 19.5184000 -3.9204386  9.8379162 12.4537235 15.9105630 16.3833266
#> 2013 17.0650427 -7.6380866 13.1920743  7.6561010 10.9523269 15.2602219
#>             Jul        Aug        Sep        Oct        Nov        Dec
#> 2011 -4.3626429  5.3125548 -4.1225391  0.5287783  2.1622054  8.4154180
#> 2012 -6.1691951 10.6600861 -8.8836891 -2.2658838 19.8405741  7.5808462
#> 2013 18.6866001  4.3891840  4.9528539 19.1422903 14.9951908 10.3613131
#> 
#> $ts2
#>             Jan        Feb        Mar        Apr        May        Jun
#> 2011  2.1075317 15.8001359  2.1949655 16.1399351  4.2801682 15.3437855
#> 2012  3.1571762  8.3932077  4.9065010  2.1472027 12.2637276 12.0804607
#> 2013  6.5450911  7.4986473  2.9009075  0.2139675  0.6966268  9.1141284
#>             Jul        Aug        Sep        Oct        Nov        Dec
#> 2011 17.8379738 14.2003324  2.0477883 12.9515194  9.7699304 18.4422302
#> 2012 11.6444259 11.6545310  9.7440705 14.7366532 16.6135129  7.7045680
#> 2013 19.4714438 13.1005719 18.0990729 11.3003898 10.2154826 12.3880003
#> 
#> $ts3
#>           Jan      Feb      Mar      Apr      May      Jun      Jul      Aug
#> 2011 12.59638 19.75084 10.18752 17.32278 14.04742 12.70547 17.83230 18.62747
#> 2012 18.80858 17.06024 16.75530 17.97625 18.01916 14.56366 14.69751 19.99966
#> 2013 14.50377 16.79234 11.39901 15.97004 13.09541 18.14256 11.32945 17.80775
#>           Sep      Oct      Nov      Dec
#> 2011 18.57995 18.76937 17.00687 16.84999
#> 2012 10.16592 12.06091 17.78977 19.72673
#> 2013 17.27397 18.92210 14.20673 10.67758
#>