# Generate Direct Adjusted Weights for Treatment Effect Estimation

Source:`R/weights.R`

`WeightCreators.Rd`

These should primarily be used inside models. See Details.
`ate()`

creates weights to estimate the Average Treatment Effect and
`ett()`

creates weights to estimate Effect of Treatment on the Treated.

## Usage

```
ett(design = NULL, dichotomy = NULL, by = NULL, data = NULL)
ate(design = NULL, dichotomy = NULL, by = NULL, data = NULL)
```

## Arguments

- design
optional; a

`Design`

object created by one of`rct_design()`

,`rd_design()`

, or`obs_design()`

.- dichotomy
optional; a formula defining the dichotomy of the treatment variable if it isn't already

`0`

/`1`

. See details for more information. If`ett()`

or`ate()`

is called within a`lmitt()`

call that specifies a`dichotomy`

argument, that`dichotomy`

will be used if the argument here has not been specified.- by
optional; named vector or list connecting names of unit of assignment/ variables in

`design`

to unit of assignment/unitid/cluster variables in`data`

. Names represent variables in the Design; values represent variables in the data. Only needed if variable names differ.- data
optional; the data for the analysis to be performed on. May be excluded if these functions are included as the

`weights`

argument of a model.

## Details

These functions should primarily be used in the `weight`

argument of `lmitt()`

or`lm()`

. All arguments are optional if used within
those functions. If used on their own, `design`

and `data`

must
be provided.

In a `Design`

with `block`

s, the weights are generated as a
function of the ratio of the number of treated units in a block versus the
total number of units in a block.

In any blocks where that ratio is 0 or 1 (that is, all units in the block have the same treatment status), the weights will be 0. In effect this removes from the target population any block in which there is no basis for estimating either means under treatment or means under control.

If block is missing for a given observation, a weight of 0 is applied.

A `dichotomy`

is specified by a `formula`

consisting of a
conditional statement on both the left-hand side (identifying treatment
levels associated with "treatment") and the right hand side (identifying
treatment levels associated with "control"). For example, if your
treatment variable was called `dose`

and doses above 250 are
considered treatment, you might write:

`dichotomy(des) <- dose > 250 ~ dose <= 250`

The period (`.`

) can be used to assign all other units of assignment.
For example, we could have written the same treatment regime as either

`dichotomy(des) <- dose > 250 ~ .`

or

`dichotomy(des) <- . ~ dose <= 250`

The `dichotomy`

formula supports Relational Operators (see
Comparison), Logical Operators (see Logic), and `%in%`

(see
`match()`

).

The conditionals need not assign all values of treatment to control or
treatment, for example, `dose > 300 ~ dose < 200`

does not assign
`200 <= dose <= 300`

to either treatment or control. This would be
equivalent to manually generating a binary variable with `NA`

whenever `dose`

is between 200 and 300. Standard errors will reflect
the sizes of the comparison groups specified by the `dichotomy`

.

Code for the computation of the weights was contributed by Tim Lycurgus.

## Examples

```
data(simdata)
des <- rct_design(z ~ unit_of_assignment(uoa1, uoa2), data = simdata)
summary(lmitt(y ~ 1, data = simdata, design = des, weights = ate()))
#>
#> Call:
#> lmitt(y ~ 1, data = simdata, design = des, weights = ate())
#>
#> Treatment Effects :
#> Estimate Std. Error t value Pr(>|t|)
#> z. 0.1205 0.2301 0.524 0.603
#> Std. Error calculated via type "CR0"
#>
```