Skip to contents

Generates a sample from periodic white noise.

Usage

sim_pwn(n = 100, period = NA, seasonof1st = 1, scale = NULL, 
        shift = NULL, f = rnorm, ...)

Arguments

n

length of the generated sample.

period

number of seasons in an epoch.

seasonof1st

season of the first observation in the result.

scale

scale the series by this amount, a vector of length period or 1.

shift

shift the series by this amount, a vector of length period or 1.

f

a function or list of functions to generate random numbers.

...

arguments for the random number generator(s) specified by f.

Details

First a series, say \(x\), of random numbers is generated as requested by the argument f. Then, if shift and/or scale are supplied, the values are modified as follows:

$$y_t = shift_{k} + scale_{k} x_t$$

where \(k\) is the season corresponding to time \(t\). The vector \(y\) is returned.

If f is a single a function (or name of a function), then the series is generated (effectively) by the call f(n,...).

The argument f may also be a list whose \(k\)th element is itself a list specifying the random number generator for the \(k\)th season. The first element being the function (such as rnorm) and the remaining elements being parameters for that function. Parameters common to all seasons may be supplied through the ... argument.

The argument period may be omitted. In that case it is inferred from f and/or the lengths of shift and scale. Currently there is no check for consistency here.

The arguments shift and scale may be used to specify simple linear transformations of the generated values, possibly different for the different seasons. Each of them should be a vector of length period or one.

seasonof1st can be used to request the simulated time series to start from a season other than the first one. Note that whatever the value of seasonof1st, the first elements of scale, shift and f (if a list) are taken to refer to season one.

Value

A vector of length \(n\) representing a realization of a periodic white noise series. The season of the first observation is seasonof1st.

Author

Georgi N. Boshnakov

Level

0 (base)

Examples

## three equivalent ways to specify periodic white noise with
## normal innovatios, 2 seasons, s.d. = 0.5 for season 1, and 2 for season 2
sim_pwn(100, f = rnorm, scale = c(0.5, 2))
#>   [1]  0.005962568 -0.362510576  0.553477201  2.958789742 -0.573699720
#>   [6]  2.023308753 -0.316034597  0.264722639  0.240463032  0.266355255
#>  [11] -0.731432231 -1.012803561  0.769831619  0.345587237 -0.417911962
#>  [16] -1.311857408  0.528783043  0.692166980 -0.448593271  0.012530423
#>  [21]  0.298335255  3.445103616 -0.440874742 -0.759891910  0.498055008
#>  [26] -0.918241786  0.730132873  2.086492354 -0.829520485  0.847915552
#>  [31] -0.709581463 -2.929384913  0.035210486  0.113396444 -0.016354089
#>  [36]  2.528562448  0.147493943 -1.346173641  0.059794146 -1.028793018
#>  [41] -0.034055787 -2.296023824 -0.057622240  0.205872784 -0.350871744
#>  [46]  0.082461249 -0.324384175 -1.288015719 -0.102219413  0.981681835
#>  [51] -0.102668494  0.381382648  0.485012096 -0.570522156 -0.051809634
#>  [56]  1.022509082 -0.629081225  1.087651938 -0.267481793 -2.276092054
#>  [61] -0.884001885 -1.429956406 -0.585101132 -2.356896297  0.813645669
#>  [66] -2.424293331  0.498754959  1.090491283 -0.442394558 -1.222461396
#>  [71] -0.205099756  0.380818740 -0.174162464  1.653695061 -0.146343451
#>  [76] -4.330692420 -0.048108388 -3.703913692  0.468905568 -1.495372963
#>  [81] -0.557620718 -1.183012831  0.292615342 -3.837116399  0.126908396
#>  [86] -1.944483532 -0.004256724  1.358083822  0.284815683  3.005923322
#>  [91]  0.064542701 -1.402365903  1.076853608 -0.606492277  0.403789888
#>  [96]  1.861982932  0.227451049  2.850841380 -0.104495586 -2.462805558
sim_pwn(n = 100, scale = c(0.5, 2))  # rnorm is the default generator
#>   [1] -0.180301789 -1.094426599  0.163998004 -1.866599664  0.340405412
#>   [6] -2.327764800  0.877724755  2.899274729 -0.224397471  0.280134578
#>  [11] -0.186825164 -2.412868234 -1.330672987 -0.050188987 -0.017186629
#>  [16]  3.284718078 -0.997731074 -1.324341517  0.440018996  0.684774840
#>  [21]  0.060876928 -1.241522069  0.100472634 -0.471810696  0.056830557
#>  [26] -1.155858391  0.594282443  2.119872556  0.668379105 -0.734338342
#>  [31] -0.152168352 -0.700559248  0.687072381 -0.599440984  0.048817572
#>  [36]  0.762376057  0.339106278 -0.535346544  1.172982832 -1.854989311
#>  [41] -0.713278587  0.084605329  0.883721735  0.105500654  0.054863020
#>  [46]  1.726405231 -0.049486602  0.207393092  0.604242438  0.187492042
#>  [51] -0.376098259  0.789848440 -0.545760217 -2.916584850 -0.061356142
#>  [56] -2.201858383  0.290461536 -0.293894979 -0.383167308  3.245795157
#>  [61] -0.054970272  2.843409709 -0.056710524 -0.658561883  0.186730492
#>  [66]  2.059776262  1.352887524 -2.069891742 -0.091714929  2.155542615
#>  [71]  0.170810113 -0.374687248 -0.651429554 -0.557316524 -0.092376954
#>  [76] -0.163554994  0.806120897 -0.923879679 -0.788025150  0.992866147
#>  [81] -0.055976892 -0.408692800  0.317784081 -5.813347908 -0.276829126
#>  [86] -0.306903657  0.302645258 -0.522013192 -0.502569231  0.745132229
#>  [91]  0.009723088  0.221057631  0.578285218 -1.084440920 -0.624600642
#>  [96] -2.560025194 -0.511966394 -2.775301160 -0.024610557  3.621921461
sim_pwn(100, f = list(c(rnorm, 0, 0.5), c(rnorm, 0, 2)))
#>   [1] -0.049755033 -1.770678382  0.388618562 -1.012660582 -0.551298163
#>   [6]  0.326664212 -0.110822391 -0.674287713  0.283047481 -2.071903064
#>  [11] -0.177479673  0.818675856  0.392631301 -1.048446916  0.347023689
#>  [16]  1.013000747 -0.316364948 -1.009445726 -0.385979321 -1.914500658
#>  [21]  1.178908694 -0.189268717 -0.096274668  1.298878635  0.003309667
#>  [26]  0.484643599 -0.027273012 -0.117868181 -0.284103440 -3.895588143
#>  [31] -0.463487972  2.902887264 -0.567867591 -0.079879355  0.456981170
#>  [36] -1.727995382 -0.493031417 -0.403380479  0.333742707  0.522511125
#>  [41]  0.703297745 -3.036702767  0.578889480  1.434617265 -0.069376599
#>  [46]  0.493665456 -0.269660925  2.405534093 -0.539446750  1.972078541
#>  [51] -0.009281070 -1.075881198 -0.116307843 -0.980565484  0.078146771
#>  [56] -1.991032345 -0.302004877 -0.723405857  0.314517560  1.888709623
#>  [61]  0.357084785  3.584414023  0.537943051  1.856818792  1.124877759
#>  [66] -3.659875339  0.098945299  1.643756212 -0.287773159  2.072537524
#>  [71] -0.038660433  1.234840288 -0.813959945 -1.709860726  0.064961577
#>  [76]  2.129021037 -0.212836567  1.458962916  0.203005874  1.325313169
#>  [81] -0.134405093 -0.762814405 -0.690492268  1.691783556  0.018291661
#>  [86]  0.223183769 -0.676622266 -0.135540523  0.448503097  2.974196193
#>  [91] -0.914679856  1.514446753 -0.070938472 -5.748084987  0.228990889
#>  [96] -0.853084898 -0.759808757 -2.974812591  0.699527657  1.177583291