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

R语言 rockchalk包 residualCenter()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-9-27 22:44:40 | 显示全部楼层 |阅读模式
residualCenter(rockchalk)
residualCenter()所属R语言包:rockchalk

                                        Calculates a "residual-centered" interaction regression.
                                         计算“剩余为中心”的互动回归。

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

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

Given a fitted lm, this function scans for coefficients estimated from "interaction terms" by checking for colon symbols. The function then calculates the "residual centered" estimate of the interaction term and replaces the interaction term with that residual centered estimate. It works for any order of interaction, unlike other implementations of the same approach. See also function lmres in package pequod.
一个装有lm,此功能可扫描从“互动术语”检查结肠癌符号的系数估计。函数,然后计算出“剩余为中心”的交互项的估计和替换的交互项与残余中心的预算。它适用于任何命令交互,不像其他同样的方法实现。请参阅功能lmres在包pequod中。

Calculates predicted values of residual centered interaction regressions estimated in any type of regression framework (lm, glm, etc).
算出的预测值的估计在任何类型的回归框架(流明glm对应等)的剩余中心的相互作用回归。


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


  residualCenter(model)

  ## Default S3 method:
residualCenter(model)

  ## S3 method for class 'rcreg'
predict(object, newdata, ...)



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

参数:model
A fitted lm object
已安装的LM对象


参数:object
Fitted residual-centered regression from residualCenter
合身的剩余为中心的回归residualCenter


参数:newdata
A dataframe of values of the predictors for which predicted values are sought. Needs to include values for all predictors individually; need not include the interactions, since those are re-calculated inside this function.
寻求一个数据框的预测值,预测值。需要单独包括所有预测变量的值,不需要包括的相互作用,因为这些被重新计算这个函数内。


参数:...
Other parameters that will be passed to the predict method of the model.
其他参数将被传递给该模型的预测方法。


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

a regression model of the type as the input model, with the exception that the residualCentered predictor is used in place of the original interaction. The return model includes new variable centeringRegressions: a list including each of the intermediate regressions that was calculated in order to create the residual centered interaction terms. These latter objects may be necessary for diagnostics and to calculate predicted values for hypothetical values of the inputs. If there are no interactive terms, then NULL is returned.
一个回归模型作为输入模型的类型,与异常,residualCentered预测器用于代替原始相互作用。回归模型,包括新的变量centeringRegressions:一个列表,其中包括每个中间,以创造的剩余为中心的互动方面所计算出的回归。后面的这些对象可能是必要的,用于诊断和假设的输入值来计算预测值。如果没有互动的条款,则返回NULL。


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



Paul E. Johnson <pauljohn@ku.edu>




参考文献----------References----------

On the Merits of Orthogonalizing Powered and Product Terms: Implications for Modeling Interactions Among Latent Variables. Structural Equation Modeling, 13(4), 497-519.

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

lmres
lmres


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


set.seed(123)
x1 <- rnorm(100)
x2 <- rnorm(100)
x3 <- rnorm(100)
x4 <- rnorm(100)
y <- rnorm(100)
dat <- data.frame(y, x1,x2,x3,x4)
rm(x1,x2,x3,x4,y)
m1 <- lm(y~ x1*x2 + x4, data=dat)

m1RC <- residualCenter(m1)

m1RCs <- summary(m1RC)
## The stage 1 centering regressions can be viewed as well[#1阶段定心回归可以被看作是]
## lapply(m1RC$rcRegressions, summary)[#lapply(m1RC rcRegressions,总结)]

## Verify residualCenter() output against the manual calculation[对手工计算验证residualCenter()输出]
dat$x1rcx2 <- as.numeric(resid(lm(I(x1*x2) ~ x1 + x2, data=dat)))
m1m <- lm(y ~ x1 + x2 + x4 + x1rcx2, data=dat)
summary(m1m)
cbind("residualCenter"=coef(m1RC), "manual"=coef(m1m))


m2 <- lm(y~ x1*x2*x3 + x4, data=dat)
m2RC <- residualCenter(m2)
m2RCs <- summary(m2RC)

## Verify that result manually[,#验证,结果手动]
dat$x2rcx3 <- as.numeric(resid(lm(I(x2*x3) ~ x2 + x3, data=dat)))
dat$x1rcx3 <- as.numeric(resid(lm(I(x1*x3) ~ x1 + x3, data=dat)))
dat$x1rcx2rcx3 <- as.numeric( resid(lm(I(x1*x2*x3) ~ x1 + x2 + x3 + x1rcx2 + x1rcx3 + x2rcx3 , data=dat)))
(m2m <- lm(y ~ x1 + x2 + x3+ x4 + x1rcx2 + x1rcx3 + x2rcx3 + x1rcx2rcx3, data=dat))

cbind("residualCenter"=coef(m2RC), "manual"=coef(m2m))


### As good as pequod's lmres[##百戈号的lmres]
### not run because pequod generates R warnings[##无法运行,因为百戈号产生R警告]
###[##]
### if (require(pequod)){[##(需要(百戈号)){]
###  pequodm1 &lt;- lmres(y ~ x1*x2*x3 + x4, data=dat) [##pequodm1 < -  lmres(Y~X1 * X2 * X3 + X4,数据= DAT)]
###  pequodm1s &lt;- summary(pequodm1)[##pequodm1s < - 摘要(pequodm1)]
###  coef(pequodm1s)[##系数(pequodm1s)]
### }[##}]

### Works with any number of interactions. See:[##兼容于任何数目的相互作用。请参见:]

m3 <- lm(y~ x1*x2*x3*x4, data=dat)
m3RC <- residualCenter(m3)
summary(m3RC)
##'[#]
## Verify that one manually (Gosh, this is horrible to write out)[#验证一个手动(天哪,这是可怕的写出来)]
dat$x1rcx4 <- as.numeric(resid(lm(I(x1*x4) ~ x1 + x4, data=dat)))
dat$x2rcx4 <- as.numeric(resid(lm(I(x2*x4) ~ x2 + x4, data=dat)))
dat$x3rcx4 <- as.numeric(resid(lm(I(x3*x4) ~ x3 + x4, data=dat)))
dat$x1rcx2rcx4 <- as.numeric(resid(lm(I(x1*x2*x4) ~ x1 + x2 + x4 + x1rcx2 + x1rcx4 + x2rcx4, data=dat)))
dat$x1rcx3rcx4 <- as.numeric(resid(lm(I(x1*x3*x4) ~ x1 + x3 + x4 + x1rcx3 + x1rcx4 + x3rcx4, data=dat)))
dat$x2rcx3rcx4 <- as.numeric(resid(lm(I(x2*x3*x4) ~ x2 + x3 + x4 + x2rcx3 + x2rcx4 + x3rcx4, data=dat)))
dat$x1rcx2rcx3rcx4 <- as.numeric(resid(lm(I(x1*x2*x3*x4) ~ x1 + x2 + x3 + x4 + x1rcx2 + x1rcx3 + x2rcx3 + x1rcx4  + x2rcx4 + x3rcx4  + x1rcx2rcx3 + x1rcx2rcx4 + x1rcx3rcx4 + x2rcx3rcx4, data=dat)))
(m3m <- lm(y ~ x1 + x2 + x3 + x4 + x1rcx2 + x1rcx3 + x2rcx3 + x1rcx4 + x2rcx4 + x3rcx4 + x1rcx2rcx3 + x1rcx2rcx4 + x1rcx3rcx4 + x2rcx3rcx4 + x1rcx2rcx3rcx4, data=dat))

cbind("residualCenter"=coef(m3RC), "manual"=coef(m3m))

### If you want to fit a sequence of models, as in pequod, can do.[##如果你想融入一个序列的车型,在pequod,可以做的。]

tm <-terms(m2)
tmvec <- attr(terms(m2), "term.labels")
f1 <- tmvec[grep(":", tmvec, invert = TRUE)]
f2 <- tmvec[grep(":.*:", tmvec, invert = TRUE)]
f3 <- tmvec[grep(":.*:.*:", tmvec, invert = TRUE)]

## &gt; f1[#> F1]
## [1] "x1" "x2" "x3" "x4"[#[1]“×1”,“×2”×3“,”×4“]
## &gt; f2[#> F2]
## [1] "x1"    "x2"    "x3"    "x4"    "x1:x2" "x1:x3" "x2:x3"[#[1]“×1”,“×2”,“×3”,“×4”,“×1×2”“×1:x3的”“×2:x3的”]
## &gt; f3[#> F3]
## [1] "x1"       "x2"       "x3"       "x4"       "x1:x2"    "x1:x3"    "x2:x3"   [#[1]“×1”,“×2”,“×3”,“×4”,“×1×2”“×1:x3的”“×2:x3的”]
## [8] "x1:x2:x3"[#[8]“X1:X2:X3”]

f1 <- lm(as.formula(paste("y","~", paste(f1, collapse=" + "))), data=dat)
f1RC <- residualCenter(f1)
summary(f1RC)

f2 <- lm(as.formula(paste("y","~", paste(f2, collapse=" + "))), data=dat)
f2RC <- residualCenter(f2)
summary(f2RC)

f3 <- lm(as.formula(paste("y","~", paste(f3, collapse=" + "))), data=dat)
f3RC <- residualCenter(f3)
summary(f3RC)

library(rockchalk)
dat <- genCorrelatedData(1000, stde=5)

m1 <- lm(y ~ x1 * x2, data=dat)

m1mc <- meanCenter(m1)
summary(m1mc)

m1rc <- residualCenter(m1)
summary(m1rc)


newdf <- apply(dat, 2, summary)
newdf <- as.data.frame(newdf)

predict(m1rc, newdata=newdf)

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-25 14:58 , Processed in 0.024437 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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