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) forgroup = 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 (forgroup = 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 (forgroup = 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
andacro
.- beta.group
A
logical
. IfTRUE
a second group of data will be simulated and included in the returned data set. IfFALSE
,beta.acro
,beta.mesor
, andbeta.amp
arguments will be ignored.- beta.mesor
A
numeric
. The MESOR value term forgroup = 1
- beta.amp
A
numeric
. The amplitude value forgroup = 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 (forgroup = 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 inc("poisson", "binomial", "gamma", "gaussian")
.- ...
Extra arguments, including
alpha
that controls theshape
argument when sampling from a gamma distribution (whenfamily = "gamma"
; default is 1), andsd
(standard deviation) which is used when sampling from a normal distribution (whenfamily = "gaussian"
; default is 1). To specify these parameters for the beta (treatment) group, usebeta.alpha
andbeta.sd
Examples
simulate_cosinor(
n = 100,
mesor = 1,
amp = 1,
acro = 1,
period = 24,
family = "gaussian"
)
#> Y times group
#> 1 1.45178433 5.10694421 0
#> 2 0.79223151 5.61350310 0
#> 3 0.57386895 21.23261202 0
#> 4 1.81312309 23.28715865 0
#> 5 2.21458685 22.19535527 0
#> 6 2.28311401 23.62888966 0
#> 7 0.57710351 6.81138982 0
#> 8 0.06487813 23.17074518 0
#> 9 1.98347281 19.80489125 0
#> 10 -3.16522408 16.60820753 0
#> 11 0.94667392 21.29900397 0
#> 12 -1.02924176 21.49374134 0
#> 13 3.62477130 0.73290050 0
#> 14 1.95351548 9.20396343 0
#> 15 0.71295252 20.65949258 0
#> 16 0.79270079 9.67235186 0
#> 17 2.06667705 4.24423870 0
#> 18 -0.35162631 4.18088056 0
#> 19 2.01878139 14.12316666 0
#> 20 1.52595311 5.06493466 0
#> 21 2.12007754 0.83072736 0
#> 22 3.13035116 5.34896195 0
#> 23 -2.31098970 15.57113634 0
#> 24 0.66994090 8.80695566 0
#> 25 2.20842715 4.33044464 0
#> 26 0.75166788 14.96085394 0
#> 27 1.49044050 8.91879969 0
#> 28 1.12484573 7.07989379 0
#> 29 1.74526925 0.01928069 0
#> 30 0.92231854 21.09158471 0
#> 31 -0.02775734 13.10012123 0
#> 32 2.52788776 16.75426010 0
#> 33 -0.35666678 8.20109913 0
#> 34 0.76775316 0.12732479 0
#> 35 -1.09405181 7.64054420 0
#> 36 3.75089264 1.52808355 0
#> 37 -0.06179022 21.28291383 0
#> 38 1.32596654 19.56494890 0
#> 39 0.11954460 14.00615244 0
#> 40 1.28803900 21.35262926 0
#> 41 -0.85799117 19.62890489 0
#> 42 -0.60674074 13.18518963 0
#> 43 -1.20107944 12.96895999 0
#> 44 -0.06560707 17.88712445 0
#> 45 1.07924732 23.42004545 0
#> 46 1.02427528 19.76102717 0
#> 47 2.37592398 6.88470391 0
#> 48 2.58089917 8.79550570 0
#> 49 2.10166451 6.78758044 0
#> 50 1.63860779 21.14288511 0
#> 51 2.79342388 1.41056799 0
#> 52 2.34040318 4.47202594 0
#> 53 0.33160128 10.28533417 0
#> 54 1.71633323 8.36777599 0
#> 55 1.89293268 8.99630852 0
#> 56 -0.26019873 14.76487121 0
#> 57 -0.45844003 8.87767000 0
#> 58 1.43687422 3.38396392 0
#> 59 0.12471971 23.69660627 0
#> 60 1.03768568 4.18702389 0
#> 61 1.52103739 2.73064929 0
#> 62 1.14672968 16.21145974 0
#> 63 0.94276802 19.52219075 0
#> 64 0.70709696 22.86182080 0
#> 65 -0.19914856 15.18340431 0
#> 66 2.55686319 23.94053930 0
#> 67 0.41741228 12.83675118 0
#> 68 1.84914176 23.71926940 0
#> 69 1.74529100 2.12046295 0
#> 70 1.23361859 6.63700323 0
#> 71 2.06042322 3.43871011 0
#> 72 2.06927427 23.55040162 0
#> 73 -0.86391150 16.26678117 0
#> 74 -0.48735062 14.27732463 0
#> 75 0.65919818 14.82594303 0
#> 76 -0.80557485 15.32183249 0
#> 77 0.90373391 14.52421115 0
#> 78 1.38422664 21.48962260 0
#> 79 -0.16184675 21.70816694 0
#> 80 1.17278402 3.59203179 0
#> 81 1.86378081 2.27599671 0
#> 82 3.02994953 4.65314877 0
#> 83 -1.23723558 17.02427956 0
#> 84 0.73130402 10.12821876 0
#> 85 0.64984914 20.15258412 0
#> 86 1.86747269 7.01956666 0
#> 87 1.21361497 5.34053182 0
#> 88 2.70906528 4.99476036 0
#> 89 0.59931613 9.06574347 0
#> 90 0.29767561 11.71330743 0
#> 91 0.76206008 3.00459408 0
#> 92 1.01331883 0.14921379 0
#> 93 0.77887646 9.48081597 0
#> 94 -0.06646819 15.55865008 0
#> 95 -0.35049757 18.02191034 0
#> 96 0.25937966 23.11379758 0
#> 97 -0.17882519 0.28729334 0
#> 98 0.90618466 23.96651417 0
#> 99 0.50623072 11.66965558 0
#> 100 1.37961653 4.37318811 0