A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://kgoldfeld.github.io/simstudy/dev/reference/trtAssign.html below:

Assign treatment — trtAssign • simstudy

Assign treatment

trtAssign(
  dtName,
  nTrt = 2,
  balanced = TRUE,
  strata = NULL,
  grpName = "trtGrp",
  ratio = NULL
)
Arguments
dtName

data table

nTrt

number of treatment groups

balanced

indicator for treatment assignment process

strata

vector of strings representing stratifying variables

grpName

string representing variable name for treatment or exposure group

ratio

vector of values indicating relative proportion of group assignment

Value

An integer (group) ranging from 1 to length of the probability vector

Examples
dt <- genData(15)

dt1 <- trtAssign(dt, nTrt = 3, balanced = TRUE)
dt1[, .N, keyby = trtGrp]
#> Key: <trtGrp>
#>    trtGrp     N
#>     <int> <int>
#> 1:      1     5
#> 2:      2     5
#> 3:      3     5

dt2 <- trtAssign(dt, nTrt = 3, balanced = FALSE)
dt2[, .N, keyby = trtGrp]
#> Key: <trtGrp>
#>    trtGrp     N
#>     <int> <int>
#> 1:      1     3
#> 2:      2     3
#> 3:      3     9

def <- defData(varname = "male", formula = .4, dist = "binary")
dt <- genData(1000, def)
dt
#> Key: <id>
#>          id  male
#>       <int> <int>
#>    1:     1     1
#>    2:     2     0
#>    3:     3     0
#>    4:     4     1
#>    5:     5     0
#>   ---            
#>  996:   996     0
#>  997:   997     0
#>  998:   998     1
#>  999:   999     1
#> 1000:  1000     0

dt3 <- trtAssign(dt, nTrt = 5, strata = "male", balanced = TRUE, grpName = "Group")
dt3
#> Key: <id>
#>          id  male Group
#>       <int> <int> <int>
#>    1:     1     1     2
#>    2:     2     0     2
#>    3:     3     0     2
#>    4:     4     1     4
#>    5:     5     0     4
#>   ---                  
#>  996:   996     0     1
#>  997:   997     0     3
#>  998:   998     1     1
#>  999:   999     1     4
#> 1000:  1000     0     5
dt3[, .N, keyby = .(male, Group)]
#> Key: <male, Group>
#>      male Group     N
#>     <int> <int> <int>
#>  1:     0     1   121
#>  2:     0     2   121
#>  3:     0     3   120
#>  4:     0     4   120
#>  5:     0     5   121
#>  6:     1     1    79
#>  7:     1     2    79
#>  8:     1     3    79
#>  9:     1     4    80
#> 10:     1     5    80
dt3[, .N, keyby = .(Group)]
#> Key: <Group>
#>    Group     N
#>    <int> <int>
#> 1:     1   200
#> 2:     2   200
#> 3:     3   199
#> 4:     4   200
#> 5:     5   201

dt4 <- trtAssign(dt, nTrt = 5, strata = "male", balanced = FALSE, grpName = "Group")
dt4[, .N, keyby = .(male, Group)]
#> Key: <male, Group>
#>      male Group     N
#>     <int> <int> <int>
#>  1:     0     1   119
#>  2:     0     2   119
#>  3:     0     3   108
#>  4:     0     4   128
#>  5:     0     5   129
#>  6:     1     1    81
#>  7:     1     2    82
#>  8:     1     3    68
#>  9:     1     4    83
#> 10:     1     5    83
dt4[, .N, keyby = .(Group)]
#> Key: <Group>
#>    Group     N
#>    <int> <int>
#> 1:     1   200
#> 2:     2   201
#> 3:     3   176
#> 4:     4   211
#> 5:     5   212

dt5 <- trtAssign(dt, nTrt = 5, balanced = TRUE, grpName = "Group")
dt5[, .N, keyby = .(male, Group)]
#> Key: <male, Group>
#>      male Group     N
#>     <int> <int> <int>
#>  1:     0     1   119
#>  2:     0     2   113
#>  3:     0     3   123
#>  4:     0     4   120
#>  5:     0     5   128
#>  6:     1     1    81
#>  7:     1     2    87
#>  8:     1     3    77
#>  9:     1     4    80
#> 10:     1     5    72
dt5[, .N, keyby = .(Group)]
#> Key: <Group>
#>    Group     N
#>    <int> <int>
#> 1:     1   200
#> 2:     2   200
#> 3:     3   200
#> 4:     4   200
#> 5:     5   200

dt6 <- trtAssign(dt, nTrt = 3, ratio = c(1, 2, 2), grpName = "Group")
dt6[, .N, keyby = .(Group)]
#> Key: <Group>
#>    Group     N
#>    <int> <int>
#> 1:     1   200
#> 2:     2   400
#> 3:     3   400

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4