plotSlopes(rockchalk)
plotSlopes()所属R语言包:rockchalk
Assists creation of predicted value lines for values of a moderator variable.
协助创建一个调节变量的值的预测值。
译者:生物统计家园网 机器人LoveR
描述----------Description----------
This is a "simple slope" plotter for linear regression. The term "simple slopes" was coined by psychologists (Aiken and West, 1991; Cohen, et al 2002) to refer to analysis of interaction effects for particular values of a moderating variable, be it continuous or categorical. To use this function, the user should estimate a regression (with as many variables as desired, including interactions) and the resulting regression object is then supplied to this function, along with user requests for plots of certain variables.
这是一个“简单的坡”绘图仪进行线性回归。 “简单的斜坡”是杜撰的心理学家(艾肯,西,1991年,科恩等人,2002)的调节变量的特定值的互作效应分析,无论是连续的或绝对的。要使用此功能,用户应该估计一个回归(根据需要尽可能多的变量,包括相互作用)和所得到的回归对象,然后提供给该函数,随着用户请求某些变量的图。
用法----------Usage----------
plotSlopes(model = NULL, plotx = NULL, modx = NULL,
modxVals = NULL, plotPoints = TRUE, plotLegend = TRUE,
col, llwd, ...)
参数----------Arguments----------
参数:model
Required. Fitted regression object. Must have a predict method
必需的。拟合回归对象。必须有一个预测方法
参数:plotx
Required. String with name of IV to be plotted on x axis
必需的。与第四名的字符串被绘制在X轴
参数:modx
Required. String for moderator variable name. May be either numeric or factor.
必需的。主持人变量名的字符串。可能是数字或因素。
参数:modxVals
Optional. If modx is numeric, either a character string, "quantile", "std.dev.", or "table", or a vector of values for which plotted lines are sought. If modx is a factor, the default approach will create one line for each level, but the user can supply a vector of levels if a subset is desired..
可选。如果MODx是数字,无论是一个字符串,“分量”,“std.dev。”,或“表”,或一个向量的值,绘制线寻求。如果MODx是一个因素,将创建默认的方法为每个级别的一条线,但期望的水平,如果一个子集,用户可以提供一个向量..
参数:plotPoints
Optional. TRUE or FALSE: Should the plot include the scatterplot points along with the lines.
可选。 TRUE或FALSE:如果图点与线的散点图。
参数:plotLegend
Optional. TRUE or FALSE: Include a default legend. Set to FALSE if use wants to run a different legend command after the plot has been drawn.
可选。 TRUE或FALSE:包含一个默认的传说。如果设置为FALSE,如果用户想运行不同的传说命令后的图已经绘就。
参数:col
Optional. A color vector. By default, the R's builtin colors will be used, which are "black", "red", and so forth. Instead, a vector of color names can be supplied, as in c("pink","black", "gray70"). A color-vector generating function like rainbow(10) or gray.colors(5) can also be used. A vector of color names can be supplied with this function. Color names will be recycled if the plot requires more different colors than the user provides.
可选。彩色矢量。默认情况下,使用R的内置的颜色,这是“黑”,“红”,等等。相反,一个向量可以提供的颜色名称,在C(“粉红色”,“黑色”,“gray70”)。也可用于如彩虹(10)或gray.colors(5)的彩色矢量生成函数。可以提供此功能的矢量颜色的名称。如果图需要更多的用户提供了不同的颜色比颜色名称将被回收利用。
参数:llwd
An optional vector of line widths used while plotting the lines that represent the values of the factor. This applies only to the lines in the plot. The ... argument will also allow one to pass options that are parsed by plot, such as lwd. That deterimine the thickness of points in the plot.
一个可选的向量所使用的线的宽度,而绘制的线表示的因子的值。这仅适用于线中的图。该...参数也允许一个通过选项进行解析图,如随钻测井。这deterimine中的图点的厚度。
参数:...
further arguments that are passed to plot
进一步的论据,通过绘制
Details
详细信息----------Details----------
The variable plotx will be the horizontal plotting variable; it must be numeric. The variable modx is the moderator variable. It may be either a numeric or a factor variable. A line will be drawn to represent the predicted value for selected values of the moderator.
变量plotx将是水平的绘图变量,它必须是数字。变量modx是调节变量。它可以是一个数字或一个因素变量。 A线将得出,代表主持人的选定值的预测值。
The parameter modxVals is optional. It is used to fine-tune the values of the moderator that are used to create the simple slope plot. Numeric and factor moderators are treated differently. If the moderator is a numeric variable, then some particular values must be chosen for plottings. If the user does not specify the parameter modxVals, then lines will be drawn for the quantile values of the moderator. If the moderator is a factor, then lines are drawn for each different value of the factor variable, unless the user specifies a subset of levels with the modxVals parameter.
参数modxVals是可选的。它是用来微调值的调节剂,用于创建简单的斜率积。数字和因素的主持人是区别对待的。如果主持人是一个数值变量,那么一些特定的值必须被为plottings选择。如果用户没有指定参数modxVals,然后线将被绘制的分量的值的调节剂。如果主持人是一个因素,那么线绘制的因素变量为每一个不同的值,除非用户指定的一个子集与modxVals参数水平。
For numeric moderators, the user may specify a vector of values for the numeric moderator variable, such as c(1,2,3). The user may also specify an algorithm, either "quantile" (which would be selected by default) or "std.dev." The alternative method at this time is "std.dev.", which causes 5 lines to be drawn. These lines are the "standard deviations about the mean of modx" lines, at which modx is set at mean - k* standard deviation, and k takes on values -2, -1, 0, 1, 2.
对于数字调节剂中,用户可以指定的数值调节变量,如c(1,2,3)的值的矢量。用户还可以指定一个算法,无论是“分量”(这将被默认选中)或“std.dev。”在这个时间的另一种方法是“std.dev。”,这会导致5条线要绘制。这些线是“modx”线,有关的平均值的标准偏差在哪些MODx是设置在平均 - 的k *标准偏差,并且k采用的值-2,-1,0,1,2 。
Here is a wrinkle. There can be many variables in a regression model, and we are plotting only for the plotx and modx variables. How should we calculate predicted values when the values of the other variables are required? For the other variables, the ones that are not explicitly inlcluded in the plot, we use the mean and mode, for numeric or factor variables (respectively). Those values can be reviewed in the newdata object that is created as a part of the output from this function
这里是皱纹。在回归模型可以有许多变数,我们正在策划plotx和modx变量。我们应该如何计算预测值,其他变量的值时,需要吗?对于其他变量,那些没有被明确自购的图,我们使用的均值和模式,为数字或因子变量(分别)。这些值可以进行审查,newdata对象被创建作为输出的一部分,从这个函数
值----------Value----------
The plot is drawn on the screen, and the return object includes the "newdata" object that was used to create the plot, along with the "modxVals" vector, the values of the moderator for which lines were drawn. It also includes the call that generated the plot.
该图在屏幕上绘制,返回的对象包括“newdata”对象,它被用来创造的图,以及“modxVals”的向量,主持人的行画的价值。它也包含了调用,生成的图。
(作者)----------Author(s)----------
Paul E. Johnson <pauljohn@ku.edu>
参考文献----------References----------
Testing and Interpreting Interactions. Newbury Park, Calif: Sage Publications.
(2002). Applied Multiple Regression/Correlation Analysis for the Behavioral Sciences (Third.). Routledge Academic.
参见----------See Also----------
plotCurves and testSlopes
plotCurves和testSlopes
实例----------Examples----------
set.seed(12345)
x1 <- rnorm(100)
x2 <- rnorm(100)
x3 <- rnorm(100)
x4 <- rnorm(100)
xcat1 <- gl(2,50, labels=c("M","F"))
xcat2 <- cut(rnorm(100), breaks=c(-Inf, 0, 0.4, 0.9, 1, Inf), labels=c("R", "M", "D", "P", "G"))
dat <- data.frame(x1, x2, x3, x4, xcat1, xcat2)
rm(x1, x2, x3, x4, xcat1, xcat2)
##ordinary regression. [#普通的回归。]
dat$y <- with(dat, 0.03 + 0.1*x1 + 0.1*x2 + 0.4*x3 -0.1*x4 + 2*rnorm(100))
m1 <- lm(y ~ x1 + x2 +x3 + x4, data=dat)
## These will be parallel lines emf [#这将是平行线电动势]
plotSlopes(m1, plotx="x1", modx="x2")
plotSlopes(m1, plotx="x1", modx="x2", modxVals=c(-0.5,0,0.5))
plotSlopes(m1, plotx="x1", modx="x2", modxVals="std.dev.", main="A plotSlopes result with \"std.dev.\" values of modx")
plotSlopes(m1, plotx="x1", modx="x2", modxVals="std.dev.", ylab="Call Y What You Want")
plotSlopes(m1, plotx="x1", modx="x2")
plotSlopes(m1, plotx="x4", modx="x1")
## now some numeric interactions worth plotting[#现在一些数字绘图的相互作用值得]
dat$y2 <- with(dat, 0.03 + 0.1*x1 + 0.1*x2 + 0.25*x1*x2 + 0.4*x3 -0.1*x4 + 1*rnorm(100))
m2 <- lm(y2 ~ x1*x2 + x3 + x4, data=dat)
summary(m2)
plotSlopes(m2, plotx="x1", modx="x2")
plotSlopes(m2, plotx="x1", modx="x2", modxVals=c( -2, -1, 0, 1))
plotSlopes(m2, plotx="x2", modx="x1", modxVals="std.dev.")
plotSlopes(m2, plotx="x2", modx="x1", modxVals="std.dev.", xlab="Any label You Want")
## Catch output, send to testSlopes[捕捉输出,发送到testSlopes]
m2ps1 <- plotSlopes(m2, plotx="x1", modx="x2")
testSlopes(m2ps1)
### Examples with categorical Moderator variable[##示例主持人变量分类]
stde <- 8
dat$y3 <- with(dat, 3 + 0.5*x1 + 1.2 * (as.numeric(xcat1)-1) +
-0.8* (as.numeric(xcat1)-1) * x1 + stde * rnorm(100))
m3 <- lm (y3 ~ x1 + xcat1, data=dat)
plotSlopes(m3, modx = "xcat1", plotx = "x1")
m4 <- lm (y ~ x1 * xcat1, data=dat)
summary(m4)
plotSlopes(m4, modx = "xcat1", plotx = "x1")
dat$xcat2n <- with(dat, contrasts(xcat2)[xcat2, ])
dat$y4 <- with(dat, 3 + 0.5*x1 + xcat2n %*% c(0.1, -0.2, 0.3, 0.05) + stde * rnorm(100))
m5 <- lm(y4 ~ x1 + xcat2, data=dat)
plotSlopes(m5, plotx="x1", modx="xcat2")
m6 <- lm(y4 ~ x1 * xcat2, data=dat)
plotSlopes(m6, plotx="x1", modx="xcat2")
## Make data with a more pronounced interaction[#使数据更明显的相互作用]
dat$y5 <- with(dat, 3 + 0.5*x1 + xcat2n %*% c(0.1, -0.2, 0.3, 0.05) + (xcat2n %*% c(0.-1, 0.2, -0.3, 0.25) )*x1 + stde * rnorm(100))
m7 <- lm(y4 ~ x1 * xcat2, data=dat)
plotSlopes(m7, plotx="x1", modx="xcat2")
##only plot first and third levels[#只绘制第一级和第三级]
m7ps <- plotSlopes(m7, plotx="x1", modx="xcat2", modxVals=levels(dat$xcat2)[c(1,3)])
##see what testSlopes says about this one[#看看testSlopes说,这一个]
##testSlopes(m7ps)[#testSlopes(m7ps)]
## Now examples with real data[#与实际数据的例子]
library(car)
m3 <- lm(statusquo ~ income * sex, data = Chile)
summary(m3)
plotSlopes(m3, modx = "sex", plotx = "income")
m4 <- lm(statusquo ~ region * income, data= Chile)
summary(m4)
plotSlopes(m4, modx = "region", plotx = "income")
plotSlopes(m4, modx = "region", plotx = "income", plotPoints=FALSE)
m5 <- lm(statusquo ~ region * income + sex + age, data= Chile)
summary(m5)
plotSlopes(m5, modx = "region", plotx = "income")
m6 <- lm(statusquo ~ income * age + education + sex + age, data=Chile)
summary(m6)
plotSlopes(m6, modx = "income", plotx = "age")
plotSlopes(m6, modx = "income", plotx = "age", plotPoints=FALSE)
## Should cause error because education is not numeric[#应该会导致错误,因为教育是不是数字]
## m7 <- lm(statusquo ~ income * age + education + sex + age, data=Chile)[#M7 < - LM(statusquo~收入*年龄+性别+年龄+学历,数据=智利)]
## summary(m7)[#摘要(M7)]
## plotSlopes(m7, modx = "income", plotx = "education")[#plotSlopes(M7,MODx的“收入”,plotx =“教育”)]
## Should cause error because "as.numeric(education") not same as[#应该会导致错误,因为“as.numeric(教育)不一样]
## plotx="education"[#plotx =“教育”]
## m8 <- lm(statusquo ~ income * age + as.numeric(education) + sex + age, data=Chile)[#M8 < - LM(statusquo~收入*年龄+ as.numeric(教育)+性别+年龄,数据=智利)]
## summary(m8)[#摘要(M8)]
## plotSlopes(m8, modx = "income", plotx = "education")[#plotSlopes(M8,MODx的“收入”,plotx =“教育”)]
## Still fails. [#仍然失败。]
## plotSlopes(m8, modx = "income", plotx = "as.numeric(education)")[#plotSlopes(M8,MODx的“收入”,plotx =的“as.numeric(教育),”)]
## Must recode variable first so that variable name is coherent[#第一次,这样的变量名是一致的,必须重新编码的变量]
Chile$educationn <- as.numeric(Chile$education)
m9 <- lm(statusquo ~ income * age + educationn + sex + age, data=Chile)
summary(m9)
plotSlopes(m9, modx = "income", plotx = "educationn")
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|