strata: Generate a Basis Matrix of Indicator Variables

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/strata.R

Description

The function generates a basis matrix including indicator variables defining intervals (strata), through dummy parameterization. It is meant to be used internally by onebasis and crossbasis and not directly run by the users.

Usage

1
strata(x, df=1, breaks=NULL, ref=1, intercept=FALSE)

Arguments

x

the predictor variable. Missing values are allowed.

df

dimension of the basis, equal to the number of strata. They depend on breaks if provided.

breaks

internal cut-off points defining the strata as right-open intervals. If provided, they determine df.

ref

interval used as reference category. Default to the first stratum. See Details below.

intercept

logical. If TRUE, an intercept is included in the basis matrix. See Details below.

Details

The strata are defined by right-open intervals specified through breaks. If these are not provided, a number of intervals defined by df is placed at equally-spaced quantiles. This step is performed through an internal call to cut.

The argument ref indentifies the reference category, specified by excluding the related stratum in the dummy parameterization of the basis. This defines control-treatment contrasts, where each interval is compared with the baseline (see contrast). If set to 0 (when intercept=TRUE), it provides a different parameterization, where each interval has its own baseline.

If intercept=TRUE, an intercept is included in the model. The default (when ref is different from 0) produces an additional variable with a constant value of 1, representing the baseline.

Value

A matrix object of class "strata". It contains the attributes df, breaks, ref and intercept, with values which can be different than the arguments provided due to internal reset.

Note

This function is mainly used internally thorugh onebasis and crossbasis to create basis and cross-basis matrices, respectively. It is not exported in the namespace to avoid conflicts with the function with the same name in the package survival, and can be accessed through the triple colon operator ':::' (see Examples below).

Author(s)

Antonio Gasparrini <antonio.gasparrini@lshtm.ac.uk>

See Also

onebasis to generate basis matrices and crossbasis to generate cross-basis matrices.

See dlnm-package for an introduction to the package and for links to package vignettes providing more detailed information.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
### simple use (accessing non-exported function through ':::')
dlnm:::strata(1:5, breaks=3)
dlnm:::strata(1:5, df=3)
dlnm:::strata(1:5, df=3, intercept=TRUE)
dlnm:::strata(1:5, df=3, ref=2, intercept=TRUE)

### use as an internal function in onebasis
b <- onebasis(chicagoNMMAPS$pm10, "strata", breaks=c(20,40))
summary(b)
model <- glm(death ~ b, family=quasipoisson(), chicagoNMMAPS)
pred <- crosspred(b, model, at=0:60)
plot(pred, xlab="PM10", ylab="RR", main="RR for PM10")

Example output

This is dlnm 2.3.2. For details: help(dlnm) and vignette('dlnmOverview').
     1
[1,] 0
[2,] 0
[3,] 1
[4,] 1
[5,] 1
attr(,"df")
[1] 1
attr(,"breaks")
[1] 3
attr(,"ref")
[1] 1
attr(,"intercept")
[1] FALSE
attr(,"class")
[1] "strata" "matrix"
     1 2 3
[1,] 0 0 0
[2,] 1 0 0
[3,] 0 1 0
[4,] 0 0 1
[5,] 0 0 1
attr(,"df")
[1] 3
attr(,"breaks")
25% 50% 75% 
  2   3   4 
attr(,"ref")
[1] 1
attr(,"intercept")
[1] FALSE
attr(,"class")
[1] "strata" "matrix"
     1 2 3
[1,] 1 0 0
[2,] 1 0 0
[3,] 1 1 0
[4,] 1 0 1
[5,] 1 0 1
attr(,"df")
[1] 3
attr(,"breaks")
33.33333% 66.66667% 
 2.333333  3.666667 
attr(,"ref")
[1] 1
attr(,"intercept")
[1] TRUE
attr(,"class")
[1] "strata" "matrix"
     1 2 3
[1,] 1 1 0
[2,] 1 1 0
[3,] 1 0 0
[4,] 1 0 1
[5,] 1 0 1
attr(,"df")
[1] 3
attr(,"breaks")
33.33333% 66.66667% 
 2.333333  3.666667 
attr(,"ref")
[1] 2
attr(,"intercept")
[1] TRUE
attr(,"class")
[1] "strata" "matrix"
BASIS FUNCTION
observations: 5114 
range: -3.049835 356.1768 
df: 2 
fun: strata 
df: 2 
breaks: 20 40 
ref: 1 
intercept: FALSE 

dlnm documentation built on Oct. 7, 2021, 5:09 p.m.