找回密码
 注册
查看: 703|回复: 0

R语言 rms包 contrast.rms()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-9-27 19:09:39 | 显示全部楼层 |阅读模式
contrast.rms(rms)
contrast.rms()所属R语言包:rms

                                        General Contrasts of Regression Coefficients
                                         回归系数的一般对比

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

This function computes one or more contrasts of the estimated regression coefficients in a fit from one of the functions in rms, along with standard errors, confidence limits, t or Z statistics, P-values. General contrasts are handled by obtaining the design matrix for two sets of predictor settings (a, b) and subtracting the corresponding rows of the two design matrics to obtain a new contrast design matrix for testing the a - b differences.  This allows for quite general contrasts (e.g., estimated differences in means between a 30 year old female and a 40 year old male). This can also be used to obtain a series of contrasts in the presence of interactions (e.g., female:male log odds ratios for several ages when the model contains age by sex interaction).  Another use of contrast is to obtain center-weighted (Type III test) and subject-weighted (Type II test) estimates in a model containing treatment by center interactions.  For the latter case, you can specify type="average" and an optional weights vector to average the within-center treatment contrasts. The design contrast matrix computed by contrast.rms can be used by the bootplot and confplot functions to obtain bootstrap nonparametric confidence intervals for contrasts.
此函数计算一个或多个适合RMS中的功能之一,随着标准误,置信区间,t或Z统计量,P值的估计回归系数的对比。一般处理的对比获得设计矩阵的预测设置两套(a,b)和两个设计基质中减去相应的行获得一个新的对比设计矩阵,用于测试的a - b差异。这使得相当普遍的反差(例如,一个30岁的女性和40岁男性在装置之间的差异估计)。这也可以用于获得一系列相互作用的存在下(例如,女性:男性log的比值比在型号为几个年龄包含按性别相互作用的年龄)的对比。另一位使用contrast的是获得中央重点测光(类型III试验),并须加权(II型试验)估计模型中的治疗中心互动。对于后一种情况下,你可以指定type="average"和一个可选的weights向量,平均中心内治疗的对比。设计对比矩阵计算contrast.rmsbootplot和confplot函数可以使用,以获得引导非参数的置信区间对比。

By omitting the b argument, contrast can be used to obtain an average or weighted average of a series of predicted values, along with a confidence interval for this average.  This can be useful for "unconditioning" on one of the predictors (see the next to last example).
通过省略b参数,contrast可以使用,得到一个平均或加权平均的一系列预测值,以及与该平均的置信区间。这可能是有用的“unconditioning”之一的预测(参见下最后一个例子)。

Specifying type="joint", and specifying at least as many contrasts as needed to span the space of a complex test, one can make multiple degree of freedom tests flexibly and simply.  Redundant contrasts will be ignored in the joint test.  See the examples below. These include an example of an "incomplete interaction test" involving only two of three levels of a categorical variable (the test also tests the main effect).
指定type="joint",并指定至少在许多需要跨越的空间,复杂的测试对比,可以自由测试的多自由度灵活和简单。冗余对比的联合测试将被忽略。请参见下面的例子。其中包括一个“不完整的互动测试”只有两三个层次的分类变量(测试还将测试的主要作用)的一个例子。

When more than one contrast is computed, the list created by contrast.rms is suitable for plotting (with error bars or bands) with xYplot or Dotplot (see the last example before the type="joint" examples).
当一个以上的对比计算,该列表创建contrast.rms的图(误差线或带)与xYplot或Dotplot(<X前看到的最后一个例子是合适的>的例子)。


用法----------Usage----------


contrast(fit, ...)
## S3 method for class 'rms'
contrast(fit, a, b, cnames=NULL,
         type=c("individual", "average", "joint"),
         conf.type=c("individual","simultaneous"),
         weights="equal", conf.int=0.95, tol=1e-7, ...)

## S3 method for class 'contrast.rms'
print(x, X=FALSE, fun=function(u)u, jointonly=FALSE, ...)



参数----------Arguments----------

参数:fit
a fit of class "rms"  
一个合适的类"rms"


参数:a
a list containing settings for all predictors that you do not wish to set to default (adjust-to) values.  Usually you will specify two variables in this list, one set to a constant and one to a sequence of values, to obtain contrasts for the sequence of values of an interacting factor.  The gendata function will generate the necessary combinations and default values for unspecified predictors.  
一个列表,其中包含所有的预测,你不希望设置为默认值(调整)值设置为。通常你会在此列表中指定两个变量,一个设置为一个常数和一个序列的值,获得对比的相互作用系数的值的顺序。 gendata函数将产生必要的组合和默认值未指定的预测。


参数:b
another list that generates the same number of observations as a, unless one of the two lists generates only one observation.  In that case, the design matrix generated from the shorter list will have its rows replicated so that the contrasts assess several differences against the one set of predictor values.  This is useful for comparing multiple treatments with control, for example.  If b is missing, the design matrix generated from a is analyzed alone.  
另一份名单产生相同的若干意见a,除非两个列表仅生成一个观察。在这种情况下,从短的列表生成的设计矩阵将有其行复制,以便对比评估对一组的预测值的几个不同。进行比较的多个处理的控制中,例如,这是非常有用的。如果b缺失,从设计矩阵生成的a单独进行分析。


参数:cnames
vector of character strings naming the contrasts when type!="average".  Usually cnames is not necessary as contrast.rms tries to name the contrasts by examining which predictors are varying consistently in the two lists.  cnames will be needed when you contrast "non-comparable" settings, e.g., you compare list(treat="drug", age=c(20,30)) with list(treat="placebo"), age=c(40,50))  
向量的字符串命名的对比,当type!="average"。通常cnames是没有必要的,因为contrast.rms试图命名的反差,通过审查的预测不同的两个列表中的一致。 cnames将需要时相反,“不具有可比性”的设置,例如,你比较list(treat="drug", age=c(20,30))与list(treat="placebo"), age=c(40,50)),


参数:type
set type="average" to average the individual contrasts (e.g., to obtain a Type II or III contrast).  Set type="joint" to jointly test all non-redundant contrasts with a multiple degree of freedom test and no averaging.  
设置type="average"平均个体的对比(例如,II类或III对比)。设置type="joint":,共同测试所有非冗余相反,一个多自由度的自由测试,并没有平均的。


参数:conf.type
The default type of confidence interval computed for a given individual (1 d.f.) contrast is a pointwise confidence interval.  Set conf.type="simultaneous" to use the multcomp package's glht and confint functions to compute confidence intervals with simultaneous (family-wise) coverage, thus adjusting for multiple comparisons.  Note that individual P-values are not adjusted for multiplicity.  
某一个人(DF)对比计算的置信区间的默认类型是一个逐点置信区间。设置conf.type="simultaneous"使用multcomp包的glht和confint功能,计算置信区间的同时(家庭明智的)的覆盖范围,从而调整的多重比较。需要注意的是个人的P-值不调整多样性。


参数:weights
a numeric vector, used when type="average", to obtain weighted contrasts  
一个数值向量,用时type="average",获得加权对比


参数:conf.int
confidence level for confidence intervals for the contrasts  
置信水平置信区间的对比


参数:tol
tolerance for qr function for determining which contrasts are redundant, and for inverting the covariance matrix involved in a joint test
容忍qr的功能来确定哪些是多余的对比,以及参与联合测试反相的协方差矩阵


参数:...
unused
未使用的


参数:x
result of contrast
结果contrast


参数:X
set X=TRUE to  print design matrix used in computing the contrasts (or the average contrast)  
设置X=TRUE打印设计矩阵计算的对比(或平均对比)


参数:fun
a function to transform the contrast, SE, and lower and upper confidence limits before printing.  For example, specify fun=exp to anti-log them for logistic models.  
一个函数来变换的对比度,SE和在打印之前的下部和上部的置信界限。例如,指定fun=exp抗登录Logistic模型。


参数:jointonly
set to FALSE to omit printing of individual contrasts
设置为FALSE忽略个人的对比印刷


值----------Value----------

a list of class "contrast.rms" containing the elements Contrast, SE, Z, var, df.residual Lower, Upper, Pvalue, X, cnames, redundant, which denote the contrast estimates, standard errors, Z or t-statistics, variance matrix, residual degrees of freedom (this is NULL if the model was not ols), lower and upper confidence limits, 2-sided P-value, design matrix, contrast names (or NULL), and a logical vector denoting which contrasts are redundant with the other contrasts.  If there are any redundant contrasts, when the results of contrast are printed, and asterisk is printed at the start of the corresponding lines.
一类"contrast.rms"包含的元素Contrast,SE,Z,var,df.residualLower,<X列表>,Upper,Pvalue,X,cnames,表示估计的对比度,标准错误,Z,t-统计量,协方差矩阵,残差自由度(这是redundant如果模型不是NULL),下部和上部的置信限,双面P-值,设计矩阵,对比度名称(或ols),和一个逻辑向量表示对比是多余的,其他的对比。如果有任何冗余的对比,得出结果后,NULL被打印,并且星号被打印在开始的相应行。


(作者)----------Author(s)----------



Frank Harrell<br>
Department of Biostatistics<br>
Vanderbilt University School of Medicine<br>
f.harrell@vanderbilt.edu




参见----------See Also----------

Predict, gendata, bootcov, summary.rms, anova.rms,
Predict,gendata,bootcov,summary.rms,anova.rms,


实例----------Examples----------


set.seed(1)
age <- rnorm(200,40,12)
sex <- factor(sample(c('female','male'),200,TRUE))
logit <- (sex=='male') + (age-40)/5
y <- ifelse(runif(200) <= plogis(logit), 1, 0)
f <- lrm(y ~ pol(age,2)*sex)
# Compare a 30 year old female to a 40 year old male[一个30岁的女性到40岁的男性进行比较]
# (with or without age x sex interaction in the model)[(带或不带年龄在模型中的X性互动)]
contrast(f, list(sex='female', age=30), list(sex='male', age=40))


# For a model containing two treatments, centers, and treatment[对于模型包含两个治疗中心,治疗]
# x center interaction, get 0.95 confidence intervals separately[X中心的互动,分别获得0.95的置信区间]
# by cente[由cente]
center <- factor(sample(letters[1:8],500,TRUE))
treat  <- factor(sample(c('a','b'),  500,TRUE))
y      <- 8*(treat=='b') + rnorm(500,100,20)
f <- ols(y ~ treat*center)


lc <- levels(center)
contrast(f, list(treat='b', center=lc),
            list(treat='a', center=lc))


# Get 'Type III' contrast: average b - a treatment effect over[获得III型平均B  - 的治疗效果对比:]
# centers, weighting centers equally (which is almost always[中心,加权平均(这是几乎总是]
# an unreasonable thing to do)[不合理的事)]
contrast(f, list(treat='b', center=lc),
            list(treat='a', center=lc),
         type='average')


# Get 'Type II' contrast, weighting centers by the number of[的数目,获取“类型II”的对比度,加权中心]
# subjects per center.  Print the design contrast matrix used.[科目每个中心。打印设计的对比矩阵。]
k <- contrast(f, list(treat='b', center=lc),
                 list(treat='a', center=lc),
              type='average', weights=table(center))
print(k, X=TRUE)
# Note: If other variables had interacted with either treat [注:如果其他变量的相互作用,无论是治疗。]
# or center, we may want to list settings for these variables[或中心,我们可能要列出这些变量的设置]
# inside the list()'s, so as to not use default settings[列表()的内部,从而不使用默认设置]


# For a 4-treatment study, get all comparisons with treatment 'a'[4处理的研究,所有的比较与治疗“”]
treat  <- factor(sample(c('a','b','c','d'),  500,TRUE))
y      <- 8*(treat=='b') + rnorm(500,100,20)
dd     <- datadist(treat,center); options(datadist='dd')
f <- ols(y ~ treat*center)
lt <- levels(treat)
contrast(f, list(treat=lt[-1]),
            list(treat=lt[ 1]),
         cnames=paste(lt[-1],lt[1],sep=':'), conf.int=1-.05/3)


# Compare each treatment with average of all others[比较各处理与所有其他人的平均]
for(i in 1:length(lt)) {
  cat('Comparing with',lt[i],'\n\n')
  print(contrast(f, list(treat=lt[-i]),
                    list(treat=lt[ i]), type='average'))
}
options(datadist=NULL)

# Six ways to get the same thing, for a variable that[六种方式得到同样的事情,对于一个变量,]
# appears linearly in a model and does not interact with[线性模型中的出现,不与]
# any other variables.  We estimate the change in y per[任何其他的变量。我们估计Y的改变每]
# unit change in a predictor x1.  Methods 4, 5 also[单位变化的预测X1。方法4,图5还]
# provide confidence limits.  Method 6 computes nonparametric[提供自信的限制。方法计算非参数]
# bootstrap confidence limits.  Methods 2-6 can work[引导的置信度。 2-6可以工作的方法]
# for models that are nonlinear or non-additive in x1.[的模型,是非线性的或非添加剂在x1。]
# For that case more care is needed in choice of settings[这种情况下,更需要谨慎选择设置]
# for x1 and the variables that interact with x1.[为x1和交互的变量与x1。]


## Not run: [#不运行:]
coef(fit)['x1']                            # method 1[方法1]
diff(predict(fit, gendata(x1=c(0,1))))     # method 2[方法2]
g &lt;- Function(fit)                         # method 3[方法3]
g(x1=1) - g(x1=0)
summary(fit, x1=c(0,1))                    # method 4[方法4]
k &lt;- contrast(fit, list(x1=1), list(x1=0)) # method 5[方法5]
print(k, X=TRUE)
fit &lt;- update(fit, x=TRUE, y=TRUE)               # method 6[方法6]
b <- bootcov(fit, B=500, coef.reps=TRUE)
bootplot(b, X=k$X)    # bootstrap distribution and CL[引导分布和CL]


# In a model containing age, race, and sex,[在模型中包含年龄,种族,性别,]
# compute an estimate of the mean response for a[用于计算的估计值的平均响应]
# 50 year old male, averaged over the races using[50岁的男性,平均种族使用]
# observed frequencies for the races as weights[观察到的频率作为权重的比赛]


f <- ols(y ~ age + race + sex)
contrast(f, list(age=50, sex='male', race=levels(race)),
         type='average', weights=table(race))

## End(Not run)[#(不执行)]


# Plot the treatment effect (drug - placebo) as a function of age[作为年龄的函数绘制的治疗效果(药物 - 安慰剂)]
# and sex in a model in which age nonlinearly interacts with treatment[和在哪个年龄段性模型中的非线性交互处理]
# for females only[只为女性]

set.seed(1)
n <- 800
treat <- factor(sample(c('drug','placebo'), n,TRUE))
sex   <- factor(sample(c('female','male'),  n,TRUE))
age   <- rnorm(n, 50, 10)
y     <- .05*age + (sex=='female')*(treat=='drug')*.05*abs(age-50) + rnorm(n)
f     <- ols(y ~ rcs(age,4)*treat*sex)
d     <- datadist(age, treat, sex); options(datadist='d')

# show separate estimates by treatment and sex[分别显示处理和性别的估计]

plot(Predict(f, age, treat, sex='female'))
plot(Predict(f, age, treat, sex='male'))
ages  <- seq(35,65,by=5); sexes <- c('female','male')
w     <- contrast(f, list(treat='drug',    age=ages, sex=sexes),
                     list(treat='placebo', age=ages, sex=sexes))
# add conf.type="simultaneous" to adjust for having done 14 contrasts[添加conf.type =“同步”调整为我做了14对比]
xYplot(Cbind(Contrast, Lower, Upper) ~ age | sex, data=w,
       ylab='Drug - Placebo')
xYplot(Cbind(Contrast, Lower, Upper) ~ age, groups=sex, data=w,
       ylab='Drug - Placebo', method='alt bars')
options(datadist=NULL)


# Examples of type='joint' contrast tests[型的例子=联合的对比试验]

set.seed(1)
x1 <- rnorm(100)
x2 <- factor(sample(c('a','b','c'), 100, TRUE))
dd <- datadist(x1, x2); options(datadist='dd')
y  <- x1 + (x2=='b') + rnorm(100)

# First replicate a test statistic from anova()[首先复制从方差分析的检验统计量()]

f <- ols(y ~ x2)
anova(f)
contrast(f, list(x2=c('b','c')), list(x2='a'), type='joint')

# Repeat with a redundancy; compare a vs b, a vs c, b vs c[重复与冗余;比较A对B,与C,B与C]

contrast(f, list(x2=c('a','a','b')), list(x2=c('b','c','c')), type='joint')

# Get a test of association of a continuous predictor with y[的连续测试协会预测与Y]
# First assume linearity, then cubic[首先假设线性,然后立方米]

f <- lrm(y>0 ~ x1 + x2)
anova(f)
contrast(f, list(x1=1), list(x1=0), type='joint')  # a minimum set of contrasts[最少的一组对比]
xs <- seq(-2, 2, length=20)
contrast(f, list(x1=0), list(x1=xs), type='joint')

# All contrasts were redundant except for the first, because of[所有的对比是多余的,因为除了第一]
# linearity assumption[线性假设]

f <- lrm(y>0 ~ pol(x1,3) + x2)
anova(f)
contrast(f, list(x1=0), list(x1=xs), type='joint')
print(contrast(f, list(x1=0), list(x1=xs), type='joint'), jointonly=TRUE)

# All contrasts were redundant except for the first 3, because of[所有的对比是多余的,因为除了第3]
# cubic regression assumption[三次回归的假设]

# Now do something that is difficult to do without cryptic contrast[现在做的东西,是很难做到的没有加密的对比]
# matrix operations: Allow each of the three x2 groups to have a different[矩阵操作:允许每个3×2组有不同的]
# shape for the x1 effect where x1 is quadratic.  Test whether there is[形状为x1的影响,其中X1为二次。检验是否有]
# a difference in mean levels of y for x2='b' vs. 'c' or whether[y的平均水平的差异X2 =B和C或是否]
# the shape or slope of x1 is different between x2='b' and x2='c' regardless[之间χ2=b的和x2 =c的无论是不同的形状或斜坡的x1]
# of how they differ when x2='a'.  In other words, test whether the mean[它们之间的区别时,X2 =A。换句话说,测试是否意味着]
# response differs between group b and c at any value of x1.[B组和C之间的任何值X1的响应不同。]
# This is a 3 d.f. test (intercept, linear, quadratic effects) and is[这是一个3 D.F.试验(截距,线性,二次效果),并且是]
# a better approach than subsetting the data to remove x2='a' then[一个更好的方法比数据集的子集,X2 =A,然后删除]
# fitting a simpler model, as it uses a better estimate of sigma from[装修一个简单的模型,因为它使用一个更好的估计西格玛]
# all the data.[所有的数据。]

f <- ols(y ~ pol(x1,2) * x2)
anova(f)
contrast(f, list(x1=xs, x2='b'),
            list(x1=xs, x2='c'), type='joint')

# Note: If using a spline fit, there should be at least one value of[注意:如果使用的花键配合,应该有至少有一个值]
# x1 between any two knots and beyond the outer knots.[X1之间任何两个节点及以后外结。]
options(datadist=NULL)

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-24 11:48 , Processed in 0.033843 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表