rwe_cut: Create strata

View source: R/psrwe_ps_est.R

rwe_cutR Documentation

Create strata

Description

Cut a sequence of numbers into bins.

The cut points are chosen such that there will with equal numbers in each bin for x. By default, values of y that are outside the range of x will be excluded from the bins, unless they are in the keep_inx.

Usage

rwe_cut(
  x,
  y = x,
  breaks = 5,
  keep_inx = NULL,
  trim_ab = c("both", "above", "below", "none")
)

Arguments

x

Vector of values based on which cut points will be determined

y

Vector of values to be cut, default to be the same as x

breaks

Number of cut points

keep_inx

Indices of y that will be categorized as 1 or the largest bin even if their values are out of range of x, i.e. the y's that will not be trimmed

trim_ab

Trim external subjects who are above or below the range of current study. Default both trims both above and below. Other options include above for above only, below for below only, and none for no trimming.

Value

A vector of stratum assignment for y. The y's that are outside the range of x and not in keep_inx are assigned NA in the result.

Examples


x <- rnorm(100,  mean = 0, sd = 1)
y <- rnorm(1000, mean = 1, sd = 2)
rwe_cut(x, y, breaks = 5)


olssol/psrwe documentation built on July 17, 2024, 4:06 p.m.