Skip to contents

This function simulates data from a cosinor model with a single covariate, where the time scale is month, and optionally allows for single covariate effects on the mean, amplitude, and acrophase.

Usage

simulate_cosinor(
  n,
  mesor,
  amp,
  acro,
  period = 24,
  n_components,
  beta.group = FALSE,
  beta.mesor,
  beta.amp,
  beta.acro,
  n_period = 1,
  family = c("gaussian", "poisson", "binomial", "gamma"),
  ...
)

Arguments

n

The sample size. An integer greater than 0.

mesor

A numeric. The MESOR (midline estimating statistic of rhythm) for group = 0. The MESOR is independent of the cosinor components, so only one value is allowed even if there are multiple components in the data being simulated.

amp

A numeric. The amplitude value (for group = 0 if grouped data are being simulated (beta.group = TRUE)). If simulating data with multiple components, specify a vector with values for each component. E.g: amp = c(5, 10).

acro

A numeric. The acrophase value in radians (for group = 0 if grouped data are being simulated (beta.group = TRUE)). If simulating data with multiple components, specify a vector with values for each component. E.g: acr = c(0, pi) for two components.

period

The period of the rhythm data (for group = 0 if grouped data are being simulated (beta.group = TRUE)). If simulating data with multiple components, specify a vector with values for each component. E.g: period = c(12, 6) for two components.

n_components

The number of components in the model. This must match the length of the inputs for amp and acro.

beta.group

A logical. If TRUE a second group of data will be simulated and included in the returned data set. If FALSE, beta.acro, beta.mesor, and beta.amp arguments will be ignored.

beta.mesor

A numeric. The MESOR value term for group = 1

beta.amp

A numeric. The amplitude value for group = 1. If simulating data with multiple components, specify a vector with values for each component. E.g: amp = c(2, 8).

beta.acro

A numeric. The acrophase value in radians (for group = 1. If simulating data with multiple components, specify a vector with values for each component. E.g: acr = c(2, 5) for two components.

n_period

A numeric. The number of cycles of the rhythm to be simulated.

family

A character. The family (see ?family) of the simulated dataset. Can handle values in c("poisson", "binomial", "gamma", "gaussian").

...

Extra arguments, including alpha that controls the shape argument when sampling from a gamma distribution (when family = "gamma"; default is 1), and sd (standard deviation) which is used when sampling from a normal distribution (when family = "gaussian"; default is 1). To specify these parameters for the beta (treatment) group, use beta.alpha and beta.sd

Value

Returns simulated data in a data.frame.

Examples

simulate_cosinor(
  n = 100,
  mesor = 1,
  amp = 1,
  acro = 1,
  period = 24,
  family = "gaussian"
)
#>                Y      times group
#> 1    1.194480619 18.5688837     0
#> 2    1.389274444 20.8856291     0
#> 3    1.522773039 20.4608388     0
#> 4    0.709072436 12.6873480     0
#> 5    2.331955204  8.0136858     0
#> 6    0.005229479 14.5856712     0
#> 7    2.189689300  3.6204695     0
#> 8   -0.484780570 14.3995877     0
#> 9   -0.847616844 21.2452399     0
#> 10   0.635988335  1.4361358     0
#> 11   1.136075710 23.3646671     0
#> 12   1.486555288 16.4551474     0
#> 13   1.342397966  5.7759504     0
#> 14   2.488506574  4.7712581     0
#> 15   2.816638175  7.7139340     0
#> 16   0.940177793 20.7051701     0
#> 17   0.527670379  0.2832798     0
#> 18  -0.206041328 15.0817796     0
#> 19   2.030663802  4.3882411     0
#> 20   1.576320355 13.5442148     0
#> 21   0.022808534 17.4825389     0
#> 22   1.351207269 11.6615412     0
#> 23   2.046409612  4.8826947     0
#> 24   1.556638762  9.5329781     0
#> 25  -0.004221519 20.5389053     0
#> 26   0.381366124 18.6714399     0
#> 27  -0.155842263 22.5791334     0
#> 28   1.208117267 18.0893958     0
#> 29   1.690154297  2.7864827     0
#> 30   2.319027206 23.3388290     0
#> 31   2.017359856 23.0470447     0
#> 32   2.035843196 10.5019208     0
#> 33   0.806815619 18.8192481     0
#> 34   3.457898160  2.8523049     0
#> 35   2.404329349 22.8810225     0
#> 36  -0.426309028  1.3653004     0
#> 37  -1.317045922 19.2020651     0
#> 38   0.026005373  5.0949867     0
#> 39   4.221025771  0.6331358     0
#> 40   1.496991812  6.4213729     0
#> 41  -0.367070916 10.6031626     0
#> 42   0.610886485 12.2875878     0
#> 43   2.550236585 22.4900520     0
#> 44  -0.319011891 11.5764539     0
#> 45   1.921073819 20.9175497     0
#> 46   0.479458486 21.9282940     0
#> 47   0.925199948  8.2421640     0
#> 48   0.767491859 10.7901650     0
#> 49   2.234405137  4.6322956     0
#> 50  -0.091635805 19.9102214     0
#> 51   2.463352306  6.9448170     0
#> 52   1.124294803  3.6679975     0
#> 53   2.387180241  1.9905571     0
#> 54  -0.168619285 18.2347859     0
#> 55  -0.142730060 18.6702839     0
#> 56   1.301358400  3.7402453     0
#> 57  -0.957964164 19.6956674     0
#> 58   1.476288883  9.3087544     0
#> 59  -0.931218761 10.1575732     0
#> 60   0.583219624  1.7622496     0
#> 61   0.156621360 16.4974746     0
#> 62   1.160878476 19.1097546     0
#> 63   2.103601848  6.7950034     0
#> 64   1.184154958 20.9746699     0
#> 65   3.976462623  5.6267204     0
#> 66   0.928820625 12.6759496     0
#> 67   2.348837066 10.2866467     0
#> 68   0.951757162 17.9728965     0
#> 69  -0.250135304 22.3006058     0
#> 70   1.360953044 10.7532949     0
#> 71   0.611451688 12.6714357     0
#> 72   1.456978631  1.6687625     0
#> 73   3.309912880 10.9366812     0
#> 74   1.115673704 21.5399937     0
#> 75   1.126870879  8.0772658     0
#> 76   0.772875138 15.5379729     0
#> 77   1.907974723  4.6563908     0
#> 78   2.297846750  6.8793524     0
#> 79  -0.534533629 10.6739525     0
#> 80   0.670109347  0.6586068     0
#> 81   0.144273164  6.4498020     0
#> 82   0.765375015 11.2495556     0
#> 83  -0.064471953 21.6852449     0
#> 84  -1.011902534 16.6132359     0
#> 85   1.342135510  1.5699004     0
#> 86   1.453655454  1.9780354     0
#> 87   1.447242247 14.3098037     0
#> 88   0.011456027 13.0898436     0
#> 89   1.507209612  5.4916378     0
#> 90   2.604354026 16.2925070     0
#> 91  -0.254791341 21.8345813     0
#> 92   2.675787846 21.7571665     0
#> 93   2.929609197 23.9616787     0
#> 94   1.763780780  1.4292215     0
#> 95   1.306305387  0.2410029     0
#> 96   0.993103091  3.7146427     0
#> 97   2.580694386  2.3432968     0
#> 98   1.439856938 10.5228130     0
#> 99   1.315264131  8.0858015     0
#> 100 -0.855718635 13.7175800     0