使用此C功能可在数据框中定义对比度.
如果您的数据框是DF,因子变量是fct,那么
DF$fct <- C(DF$fct, contr.treatment, base=3)
Run Code Online (Sandbox Code Playgroud)
(未经测试).
使用Frank Harrell的软件包(允许许多其他功能)非常容易.
例如,对于名为"df"的数据帧
library(Hmisc)
library(rms)
dd=datadist(df)
options(datadist='dd')
(m=lrm(y ~ catvar, data=df)) #uses the mode as the reference group
summary(m, catvar=3) #using level=3 as the reference group
summary(m, catvar=0) #using level=0 as the reference group
Run Code Online (Sandbox Code Playgroud)
(并且,一些示例数据本来不错 - 您总是可以dput用来输出一个小数据集)