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
|
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 |
format.contrast |
For categorical variables. A string which specifies the print format for constrast statements.
The string has to contain the keywords |
format.scale |
A string which specifies the print format for continuous variables without units.
The string has to contain the keyword |
format.scale.unit |
A string which specifies the print format for continuous variables with units.
The string has to contain the keywords |
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)))