treatment | R Documentation |
StudySpecification
objectsAllows access to the elements which define a
StudySpecification
, enabling their extraction or replacement.
treatment(x, newdata = NULL, dichotomy = NULL, by = NULL, ...)
## S4 method for signature 'StudySpecification'
treatment(x, newdata = NULL, dichotomy = NULL, by = NULL, ...)
treatment(x) <- value
## S4 replacement method for signature 'StudySpecification'
treatment(x) <- value
units_of_assignment(x, newdata = NULL, by = NULL)
## S4 method for signature 'StudySpecification'
units_of_assignment(x, newdata = NULL, by = NULL)
units_of_assignment(x) <- value
## S4 replacement method for signature 'StudySpecification'
units_of_assignment(x) <- value
clusters(x, newdata = NULL, by = NULL)
## S4 method for signature 'StudySpecification'
clusters(x, newdata = NULL, by = NULL)
clusters(x) <- value
## S4 replacement method for signature 'StudySpecification'
clusters(x) <- value
unitids(x)
## S4 method for signature 'StudySpecification'
unitids(x)
unitids(x) <- value
## S4 replacement method for signature 'StudySpecification'
unitids(x) <- value
blocks(x, newdata = NULL, by = NULL, ...)
## S4 method for signature 'StudySpecification'
blocks(x, newdata = NULL, by = NULL, ..., implicit = FALSE)
blocks(x) <- value
## S4 replacement method for signature 'StudySpecification'
blocks(x) <- value
has_blocks(x)
forcings(x, newdata = NULL, by = NULL)
## S4 method for signature 'StudySpecification'
forcings(x, newdata = NULL, by = NULL)
forcings(x) <- value
## S4 replacement method for signature 'StudySpecification'
forcings(x) <- value
x |
a |
newdata |
optional; an additional |
dichotomy |
optional; a formula specifying how to dichotomize a
non-binary treatment variable. See the Details section of the |
by |
optional; named vector or list connecting names of unit of
assignment/unitid/cluster variables in |
... |
ignored. |
value |
replacement. Either a |
implicit |
Should a block-less |
For treatment()
, when argument binary
is FALSE
, the
treatment variable passed into the StudySpecification
is returned
as a one-column data.frame
regardless of whether it is binary or
x
has a dichotomy
If a dichotomy
is passed, a binary one-column data.frame
will be returned. If not and binary
is TRUE
, unless the
StudySpecification
has a binary treatment, treatment()
will
error. If binary
is "ifany"
, it will return the original
treatment in this case.
The one-column data.frame
returned by treatment()
is named as
entered in the StudySpecification
creation, but if a
dichotomy
is passed, the column name is "__z"
to try and
avoid any name conflicts.
For the value
when using replacers, the replacement must have the
same number of rows as the StudySpecification
(the same number of
units of assignment). The number of columns can differ (e.g. if the
StudySpecification
were defined with two variable uniquely
identifying blocks, you can replace that with a single variable uniquely
identifying blocks, as long as it respects other restrictions.)
If the replacement value is a data.frame
, the name of the columns
is used as the new variable names. If the replacement is a matrix
or vector
, the original names are retained. If reducing the number
of variables (e.g., moving from two variables uniquely identifying to a
single variable), the appropriate number of variable names are retained.
If increasing the number of variables, a data.frame
with names must
be provided.
data.frame
containing requested variable, or an updated
StudySpecification
. treatment()
works slightly differently, see
Details
.
data(simdata)
spec <- obs_spec(z ~ unit_of_assignment(uoa1, uoa2), data = simdata)
blocks(spec) # empty
blocks(spec) <- data.frame(blks = c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5))
blocks(spec)
blocks(spec) <- c(5, 5, 4, 4, 3, 3, 2, 2, 1, 1)
blocks(spec) # notice that variable is not renamed
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.