parseInteractionTerms {Publish}R Documentation

Parse interaction terms

Description

Parse interaction terms for regression tables

Usage

parseInteractionTerms(
  terms,
  xlevels,
  units,
  format.factor,
  format.contrast,
  format.scale,
  format.scale.unit,
  sep = ": ",
  ...
)

Arguments

terms

Terms of a formula

xlevels

Factor levels corresponding to the variables in terms

units

named list with unit labels. names should match variable names in formula.

format.factor

For categorical variables. A string which specifies the print format for factor labels. The string has to contain the keywords "var" and "level" which will be replaced by the name of the variable and the current level, respectively. Default is "var(level)".

format.contrast

For categorical variables. A string which specifies the print format for constrast statements. The string has to contain the keywords "var", "level" and "ref" which will be replaced by the name of the variable, the current level and the reference level, respectively.

format.scale

A string which specifies the print format for continuous variables without units. The string has to contain the keyword "var" which will be replaced by the name of the variable and the unit, respectively. Default is "var".

format.scale.unit

A string which specifies the print format for continuous variables with units. The string has to contain the keywords "var" and "unit" which will be replaced by the name of the variable and the unit, respectively. Default is "var(unit)".

sep

a character string to separate the terms. Default is ": ".

...

Not yet used

Details

Prepare a list of contrasts which combines regression coefficients to describe statistical interactions.

Value

List of contrasts which can be passed to lava::estimate.

Author(s)

Thomas A. Gerds <tag@biostat.ku.dk>

See Also

lava::estimate

Examples


tt <- terms(formula(SBP~age+sex*BMI))
xlev <- list(sex=c("male","female"),BMI=c("normal","overweight","obese"))
parseInteractionTerms(terms=tt,xlevels=xlev)
parseInteractionTerms(terms=tt,xlevels=xlev,format.factor="var level")
parseInteractionTerms(terms=tt,xlevels=xlev,format.contrast="var(level:ref)")

tt2 <- terms(formula(SBP~age*factor(sex)+BMI))
xlev2 <- list("factor(sex)"=c("male","female"))
parseInteractionTerms(terms=tt2,xlevels=xlev2)
parseInteractionTerms(terms=tt2,xlevels=xlev2,units=list(age="yrs"))


data(Diabetes)
fit <- glm(bp.2s~age*factor(gender)+BMI,data=Diabetes)
parseInteractionTerms(terms=terms(fit$formula),xlevels=fit$xlevels,
                      format.scale="var -- level:ref",units=list("age"='years'))
parseInteractionTerms(terms=terms(fit$formula),xlevels=fit$xlevels,
                      format.scale.unit="var [unit]",units=list("age"='years'))
it <- parseInteractionTerms(terms=terms(fit$formula),xlevels=fit$xlevels)
ivars <- unlist(lapply(it,function(x)attr(x,"variables")))
lava::estimate(fit,function(p)lapply(unlist(it),eval,envir=sys.parent(-1)))



[Package Publish version 2023.01.17 Index]