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    0.97932355  3.4565204     0
#> 2   -0.04675646 14.0268928     0
#> 3    1.76120779  7.4523821     0
#> 4    1.80774428 14.8343206     0
#> 5    0.50266365 11.8974671     0
#> 6   -0.45837517 18.5688837     0
#> 7   -0.59699250 20.8856291     0
#> 8    0.31920827 20.4608388     0
#> 9    2.00600191 12.6873480     0
#> 10   2.29192204  8.0136858     0
#> 11   0.78541096 14.5856712     0
#> 12   2.19455179  3.6204695     0
#> 13  -0.36688263 14.3995877     0
#> 14   1.81044646 21.2452399     0
#> 15   2.62631864  1.4361358     0
#> 16   1.13081734 23.3646671     0
#> 17   0.87957365 16.4551474     0
#> 18   1.90156228  5.7759504     0
#> 19   1.55243926  4.7712581     0
#> 20   1.11624691  7.7139340     0
#> 21  -0.84868335 20.7051701     0
#> 22   2.07210982  0.2832798     0
#> 23   0.22356140 15.0817796     0
#> 24   1.95822254  4.3882411     0
#> 25   0.66951707 13.5442148     0
#> 26  -1.26976180 17.4825389     0
#> 27   0.77653095 11.6615412     0
#> 28   2.08943812  4.8826947     0
#> 29  -0.08942339  9.5329781     0
#> 30   0.11812442 20.5389053     0
#> 31  -0.20925066 18.6714399     0
#> 32   1.47502863 22.5791334     0
#> 33   0.48422945 18.0893958     0
#> 34   3.24550746  2.7864827     0
#> 35   0.49024036 23.3388290     0
#> 36   1.88884296 23.0470447     0
#> 37   2.47979330 10.5019208     0
#> 38   1.82666233 18.8192481     0
#> 39   1.07853789  2.8523049     0
#> 40   1.60406562 22.8810225     0
#> 41   2.50698189  1.3653004     0
#> 42   1.85412523 19.2020651     0
#> 43   0.49898153  5.0949867     0
#> 44   0.93964041  0.6331358     0
#> 45   2.92119653  6.4213729     0
#> 46   0.68519047 10.6031626     0
#> 47   0.57860956 12.2875878     0
#> 48  -0.03074258 22.4900520     0
#> 49  -0.97591913 11.5764539     0
#> 50  -0.28029662 20.9175497     0
#> 51  -0.44369097 21.9282940     0
#> 52   2.55547836  8.2421640     0
#> 53   1.44084142 10.7901650     0
#> 54   3.08753088  4.6322956     0
#> 55   0.60373355 19.9102214     0
#> 56   0.86810957  6.9448170     0
#> 57   1.04717315  3.6679975     0
#> 58   2.39128089  1.9905571     0
#> 59   0.27546470 18.2347859     0
#> 60   2.26916434 18.6702839     0
#> 61   2.71001491  3.7402453     0
#> 62  -1.77012726 19.6956674     0
#> 63   2.68519693  9.3087544     0
#> 64   1.60895861 10.1575732     0
#> 65   0.45145879  1.7622496     0
#> 66   0.61722043 16.4974746     0
#> 67   1.69438709 19.1097546     0
#> 68   2.16987416  6.7950034     0
#> 69   1.98474963 20.9746699     0
#> 70   1.47445887  5.6267204     0
#> 71   0.32432027 12.6759496     0
#> 72   1.85326530 10.2866467     0
#> 73   1.09744227 17.9728965     0
#> 74   2.37837081 22.3006058     0
#> 75   2.27712579 10.7532949     0
#> 76  -0.65669859 12.6714357     0
#> 77   1.90302795  1.6687625     0
#> 78   0.14007818 10.9366812     0
#> 79   1.56897135 21.5399937     0
#> 80   2.70045490  8.0772658     0
#> 81   1.12044183 15.5379729     0
#> 82   1.61644956  4.6563908     0
#> 83   0.92685636  6.8793524     0
#> 84   0.98326242 10.6739525     0
#> 85   0.63211675  0.6586068     0
#> 86   1.21570568  6.4498020     0
#> 87  -0.41164719 11.2495556     0
#> 88   0.42306064 21.6852449     0
#> 89   0.46031616 16.6132359     0
#> 90   0.95687841  1.5699004     0
#> 91   1.47634018  1.9780354     0
#> 92   0.03036320 14.3098037     0
#> 93   0.27588505 13.0898436     0
#> 94   3.13751737  5.4916378     0
#> 95  -1.33207225 16.2925070     0
#> 96   0.23237931 21.8345813     0
#> 97   2.48993409 21.7571665     0
#> 98   2.40765836 23.9616787     0
#> 99   2.78032757  1.4292215     0
#> 100  1.45167921  0.2410029     0