Simulation of a dose-response curve with user-specified dose values and error distribution.
Usage
rdrm(
nosim,
fct,
mpar,
xerror,
xpar = 1,
yerror = "rnorm",
ypar = c(0, 1),
onlyY = FALSE
)Arguments
- nosim
numeric. The number of simulated curves to be returned.
- fct
list. Any built-in function in the package drc or a list with similar components.
- mpar
numeric. The model parameters to be supplied to
fct.- xerror
numeric or character. The distribution for the dose values.
- xpar
numeric vector supplying the parameter values defining the distribution for the dose values. If
xerroris a distribution then remember that the number of dose values also is part of this argument (the first argument).- yerror
numeric or character. The error distribution for the response values.
- ypar
numeric vector supplying the parameter values defining the error distribution for the response values.
- onlyY
logical. If TRUE then only the response values are returned (useful in simulations). Otherwise both dose values and response values (and for binomial data also the weights) are returned.
Details
The distribution for the dose values can either be a fixed set of dose values (a numeric vector) used repeatedly for creating all curves or be a distribution specified as a character string resulting in varying dose values from curve to curve.
The error distribution for the response values can be any continuous distribution
like rnorm or rgamma. Alternatively it can be the binomial
distribution rbinom.
Examples
## Simulating normally distributed dose-response data
## Model fit to simulate from
ryegrass.m1 <- drm(rootl~conc, data = ryegrass, fct = LL.4())
## 10 random dose-response curves based on the model fit
sim10a <- rdrm(10, LL.4(), coef(ryegrass.m1), xerror = ryegrass$conc)
sim10a
#> $x
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#> [1,] 0 0 0 0 0 0 0.94 0.94 0.94 1.88 1.88 1.88 3.75
#> [2,] 0 0 0 0 0 0 0.94 0.94 0.94 1.88 1.88 1.88 3.75
#> [3,] 0 0 0 0 0 0 0.94 0.94 0.94 1.88 1.88 1.88 3.75
#> [4,] 0 0 0 0 0 0 0.94 0.94 0.94 1.88 1.88 1.88 3.75
#> [5,] 0 0 0 0 0 0 0.94 0.94 0.94 1.88 1.88 1.88 3.75
#> [6,] 0 0 0 0 0 0 0.94 0.94 0.94 1.88 1.88 1.88 3.75
#> [7,] 0 0 0 0 0 0 0.94 0.94 0.94 1.88 1.88 1.88 3.75
#> [8,] 0 0 0 0 0 0 0.94 0.94 0.94 1.88 1.88 1.88 3.75
#> [9,] 0 0 0 0 0 0 0.94 0.94 0.94 1.88 1.88 1.88 3.75
#> [10,] 0 0 0 0 0 0 0.94 0.94 0.94 1.88 1.88 1.88 3.75
#> [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24]
#> [1,] 3.75 3.75 7.5 7.5 7.5 15 15 15 30 30 30
#> [2,] 3.75 3.75 7.5 7.5 7.5 15 15 15 30 30 30
#> [3,] 3.75 3.75 7.5 7.5 7.5 15 15 15 30 30 30
#> [4,] 3.75 3.75 7.5 7.5 7.5 15 15 15 30 30 30
#> [5,] 3.75 3.75 7.5 7.5 7.5 15 15 15 30 30 30
#> [6,] 3.75 3.75 7.5 7.5 7.5 15 15 15 30 30 30
#> [7,] 3.75 3.75 7.5 7.5 7.5 15 15 15 30 30 30
#> [8,] 3.75 3.75 7.5 7.5 7.5 15 15 15 30 30 30
#> [9,] 3.75 3.75 7.5 7.5 7.5 15 15 15 30 30 30
#> [10,] 3.75 3.75 7.5 7.5 7.5 15 15 15 30 30 30
#>
#> $y
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] 8.066417 7.161786 7.222872 7.433376 7.642343 7.093628 7.923545 8.284291
#> [2,] 7.505974 6.078136 6.503759 9.352759 8.065649 6.720029 5.781844 9.058972
#> [3,] 8.327354 8.645831 8.467516 6.698238 7.510698 7.972966 6.409988 8.056339
#> [4,] 9.096690 7.312124 7.864879 8.735890 7.560072 7.266967 6.735318 7.963788
#> [5,] 7.258083 7.368628 7.055604 7.881555 9.301122 7.410662 8.285907 5.714209
#> [6,] 8.925786 8.569848 8.836314 6.614582 6.187379 9.516748 7.477650 7.078747
#> [7,] 7.756834 7.929422 8.581864 7.078809 7.346530 8.146883 9.577975 6.928401
#> [8,] 6.745958 7.191619 7.892295 8.153598 7.667378 8.120790 7.654978 5.718323
#> [9,] 6.821557 7.894365 8.438348 7.674455 6.469690 6.945612 9.229277 8.995717
#> [10,] 6.432471 6.722794 8.476714 7.572785 7.125783 9.020141 8.071111 6.930408
#> [,9] [,10] [,11] [,12] [,13] [,14] [,15]
#> [1,] 7.682404 5.945141 7.216933 6.672380 3.534480 3.682829 2.271530
#> [2,] 7.918867 7.208031 5.846323 6.933062 2.748299 2.012915 4.586617
#> [3,] 7.368475 5.145932 7.872643 7.086995 2.439913 4.865038 3.591403
#> [4,] 7.136487 4.542725 5.603221 7.256139 3.473104 2.556701 2.730241
#> [5,] 7.198957 5.342127 7.880616 5.818385 4.857711 3.314165 3.127980
#> [6,] 7.839711 5.641550 4.678501 6.531467 4.267781 2.426996 3.342862
#> [7,] 9.595229 4.304123 6.371873 6.219813 3.506707 1.541592 2.231613
#> [8,] 6.915723 6.990295 9.310118 7.827924 3.052878 2.193345 2.968142
#> [9,] 8.450324 4.982754 7.405585 5.090363 3.405927 3.903577 2.018578
#> [10,] 8.549147 5.522101 7.072001 7.075904 3.291795 3.194503 3.627527
#> [,16] [,17] [,18] [,19] [,20] [,21]
#> [1,] -0.140879059 0.9380080 0.8254205 1.0379614 0.7350702 1.45249011
#> [2,] 0.191662263 0.4805241 1.1798748 1.1113034 1.1001285 0.35779707
#> [3,] 1.240025609 -0.4437699 1.7199829 1.0841137 -1.1948623 1.45354148
#> [4,] 0.187723805 -0.7442005 0.4908456 -0.1032920 0.4326651 1.23307403
#> [5,] -0.917179274 2.0086702 0.3563959 0.5159329 -0.0761879 -1.53666510
#> [6,] 2.007846286 1.3812106 1.1360886 1.2690461 1.2988363 1.29623123
#> [7,] 1.187094786 0.5637970 2.4621087 -0.5056758 -0.1282062 1.85899709
#> [8,] 0.610012833 0.7283811 0.4562212 1.9244428 1.1058905 1.56657138
#> [9,] 2.431699280 1.4385857 3.1617329 1.3540638 0.3321539 1.58547389
#> [10,] 0.008404434 1.3859897 0.9772450 -0.3431308 -0.4085134 0.03729916
#> [,22] [,23] [,24]
#> [1,] -0.4207740 1.16833992 -0.1482707
#> [2,] 1.3377319 -1.38459417 0.1999361
#> [3,] 1.1004658 0.63946903 1.6297087
#> [4,] 0.1653214 0.84414207 -0.1439696
#> [5,] 0.9388422 1.83629562 1.9284379
#> [6,] 0.2781959 -0.04695046 -0.5979337
#> [7,] 0.9842609 -0.02732443 1.7252574
#> [8,] -1.2229484 1.57082584 0.4368156
#> [9,] 0.4443086 -0.01412220 2.4056532
#> [10,] -0.4591859 -1.80289191 0.1164907
#>
## Simulating binomial dose-response data
## Model fit to simulate from
deguelin.m1 <- drm(r/n~dose, weights=n, data=deguelin, fct=LL.2(), type="binomial")
## 10 random dose-response curves
sim10b <- rdrm(10, LL.2(), coef(deguelin.m1), deguelin$dose, yerror="rbinom", ypar=deguelin$n)
sim10b
#> $x
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 5.128614 10 20.41738 30.19952 40.73803 50.11872
#> [2,] 5.128614 10 20.41738 30.19952 40.73803 50.11872
#> [3,] 5.128614 10 20.41738 30.19952 40.73803 50.11872
#> [4,] 5.128614 10 20.41738 30.19952 40.73803 50.11872
#> [5,] 5.128614 10 20.41738 30.19952 40.73803 50.11872
#> [6,] 5.128614 10 20.41738 30.19952 40.73803 50.11872
#> [7,] 5.128614 10 20.41738 30.19952 40.73803 50.11872
#> [8,] 5.128614 10 20.41738 30.19952 40.73803 50.11872
#> [9,] 5.128614 10 20.41738 30.19952 40.73803 50.11872
#> [10,] 5.128614 10 20.41738 30.19952 40.73803 50.11872
#>
#> $w
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 49 48 48 49 50 48
#> [2,] 49 48 48 49 50 48
#> [3,] 49 48 48 49 50 48
#> [4,] 49 48 48 49 50 48
#> [5,] 49 48 48 49 50 48
#> [6,] 49 48 48 49 50 48
#> [7,] 49 48 48 49 50 48
#> [8,] 49 48 48 49 50 48
#> [9,] 49 48 48 49 50 48
#> [10,] 49 48 48 49 50 48
#>
#> $y
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 9 29 39 42 48 44
#> [2,] 14 24 40 44 48 48
#> [3,] 13 24 39 41 45 45
#> [4,] 12 19 39 44 43 43
#> [5,] 5 28 36 43 42 42
#> [6,] 11 25 45 38 47 47
#> [7,] 9 20 41 40 49 47
#> [8,] 9 25 38 43 48 45
#> [9,] 11 30 38 46 47 46
#> [10,] 11 20 36 44 48 44
#>
