plotCurves(rockchalk)
plotCurves()所属R语言包:rockchalk
Assists creation of predicted value curves for regression models.
协助建立回归模型的预测值曲线。
译者:生物统计家园网 机器人LoveR
描述----------Description----------
This is similar to plotSlopes, but it accepts regressions in which there are transformed variables, such as "log(x1)". Think of this a new version of R's termplot, but it allows for interactions. It creates a plot of the predicted dependent variable against one of the numeric predictors, plotx. It draws a predicted value line for several values of modx, a moderator variable. The moderator may be a numeric or categorical moderator variable.
这是类似于plotSlopes,但它接受回归分析,其中有转化的变量,如“log(×1)”。想想R的termplot这是一个新的版本,但它允许进行交互。它创建一个图的预测因变量对一个数字的预测,plotx。它吸引了几个值modx,一个调节变量的预测值线。主持人可能是一个数值或类别的调节变量。
用法----------Usage----------
plotCurves(model = NULL, plotx = NULL, modx = NULL,
modxVals = NULL, plotPoints = TRUE, col,
envir = environment(formula(model)), ...)
参数----------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. Should the plot include the scatterplot points along with the lines.
可选。图应该包括点与线的散点图。
参数: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)的彩色矢量生成函数。可以提供此功能的矢量颜色的名称。如果图需要更多的用户提供了不同的颜色比颜色名称将被回收利用。
参数:envir
environment to search for variables.
环境为变量,以搜寻。
参数:...
further arguments that are passed to plot.
进一步的参数传递到图。
Details
详细信息----------Details----------
The user may designate which particular values of the moderator are used for calculating the predicted value lines. That is, modxVals = c( 12,22,37) would draw lines for values 12, 22, and 37 of the moderator.
用户可指定其中缓和剂的特定值被用于计算预测值线。也就是说,modxVals = c( 12,22,37)画线值12,22和37的主持人。
If the user does not specify the parameter modxVals, built-in algorithms will select the "cut points". Three algorithms have been prepared so far, quantile, std.dev., and table. If the number of unique observed values is smaller than 6, the table method is used. The 5 most frequently observed values of modx are selected. Otherwise, the quantile method is used. Predictive lines are plotted for the following percentiles 0.25,0.50,0.75. The algorithm std.dev. plots three lines, one for the mean of modx, and one for the mean minus one standard deviation, and the other for the mean plus one standard deviation.
如果用户没有指定的参数modxVals,内置算法将选择“切点”。三种算法已经准备了这么远,quantile,std.dev.,和table。如果独特的观测值的数目小于6时,table方法被使用。最常观察到的值MODx的选择。否则,位数的方法被使用。预测线被绘制为下列百分0.25,0.50,0.75。该算法std.dev.绘制三行,一个用于MODx的平均值,和一个的平均值减去一个标准偏差,和其他的平均值加上一个标准偏差。
值----------Value----------
A plot is created as a side effect, a list is returned including 1) the call, 2) a newdata object that includes information on the curves that were plotted, 3) a vector modxVals, the values for which curves were drawn.
甲图被创建作为副作用,一个列表包括:1)的呼叫,2)newdata上绘制的曲线,3)的矢量modxVals,绘制曲线的值的信息的对象,该对象包括返回。
(作者)----------Author(s)----------
Paul E. Johnson <pauljohn@ku.edu>
实例----------Examples----------
set.seed(12345)
N <- 500
x1 <- rnorm(N, m=5, s=1)
x2 <- rnorm(N)
x3 <- rnorm(N)
x4 <- rnorm(N)
xcat1 <- gl(2,50, labels=c("Monster","Human"))
xcat2 <- cut(rnorm(N), 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)
###The design matrix for categorical variables, xcat numeric[##分类变量的设计矩阵,XCAT数字]
dat$xcat1n <- with(dat, contrasts(xcat1)[xcat1, ])
dat$xcat2n <- with(dat, contrasts(xcat2)[xcat2, ])
stde <- 2
dat$y <- with(dat, 0.03 + 11.5*log(x1)*xcat1n + 0.1*x2 + 0.04*x2^2 + stde*rnorm(N))
stde <- 1
dat$y2 <- with(dat, 0.03 + 0.1*x1 + 0.1*x2 + 0.25*x1*x2 + 0.4*x3 -0.1*x4 + stde*rnorm(N))
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(N))
stde <- 8
dat$y4 <- with(dat, 3 + 0.5*x1 + xcat2n %*% c(0.1, -0.2, 0.3, 0.05) + stde * rnorm(N))
## Curvature with interaction[#曲率与互动]
m1 <- lm(y ~ log(x1)*xcat1 + x2 + I(x2^2), data=dat)
summary(m1)
plotCurves(m1, plotx="x1", modx="xcat1")
## Verify that plot by comparing against a manually contructed alternative[#验证图比较手动池莉构建的替代]
par(mfrow=c(1,2))
plotCurves(m1, plotx="x1", modx="xcat1")
newdat <- with(dat, expand.grid(x1 = plotSeq(x1, 30), xcat1=levels(xcat1)))
newdat$x2 <- with(dat, mean(x2, na.rm=TRUE))
newdat$m1p <- predict(m1, newdata=newdat)
plot( y ~ x1, data=dat, type="n")
points( y ~ x1, data=dat, col=dat$xcat1)
by(newdat, newdat$xcat1, function(dd) {lines(dd$x1, dd$m1p)})
legend("topleft", legend=levels(dat$xcat1), col=as.numeric(dat$xcat1), lty=1)
par(mfrow=c(1,1))
##Close enough![#关闭够了!]
plotCurves(m1, plotx="x2", modx="x1")
##OK[#OK]
plotCurves(m1, plotx="x2", modx="xcat1")
##OK[#OK]
m2 <- lm(y ~ log(x1)*xcat1 + xcat1*(x2 + I(x2^2)), data=dat)
summary(m2)
plotCurves(m2, plotx="x2", modx="xcat1")
##OK [#OK]
plotCurves(m2, plotx="x2", modx="x1")
##OK[#OK]
plotCurves(m2, plotx="x2", modx="x1")
##OK[#OK]
m3a <- lm(y ~ poly(x2,2) + xcat1, data=dat)
plotCurves(m3a, plotx="x2", modx="xcat1")
#OK[行]
m3b <- lm(y ~ x2 + I(x2^2) + xcat1, data=dat)
plotCurves(m3b, plotx="x2", modx="xcat1")
#OK[行]
m4 <- lm(log(y+10) ~ poly(x2, 2)*xcat1 + x1, data=dat)
summary(m4)
plotCurves(m4, plotx="x2", modx="xcat1")
#OK[行]
plotCurves(m4, plotx="x2", modx="x1")
#OK[行]
plotCurves(m4, plotx="x2", modx="xcat1", modxVals=c("Monster"))
#OK[行]
##ordinary interaction[#普通的相互作用]
m5 <- lm(y2 ~ x1*x2 + x3 +x4, data=dat)
summary(m5)
plotCurves(m5, plotx="x1", modx="x2")
plotCurves(m5, plotx="x1", modx="x2", modxVals=c( -2, -1, 0, 1, 2))
plotCurves(m5, plotx="x1", modx="x2", modxVals=c(-2 ))
plotCurves(m5, plotx="x1", modx="x2", modxVals="std.dev.")
plotCurves(m5, plotx="x1", modx="x2", modxVals="quantile")
plotCurves(m5, plotx="x3", modx="x2")
library(car)
mc1 <- lm(statusquo ~ income * sex, data = Chile)
summary(mc1)
plotCurves(mc1, modx = "sex", plotx = "income")
plotCurves(mc1, modx = "sex", plotx = "income", modxVals = "M")
mc2 <- lm(statusquo ~ region * income, data= Chile)
summary(mc2)
plotCurves(mc2, modx = "region", plotx = "income")
plotCurves(mc2, modx = "region", plotx = "income", modxVals = levels(Chile$region)[c(1,4)])
plotCurves(mc2, modx = "region", plotx = "income", modxVals = c("S","M","SA"))
plotCurves(mc2, modx = "region", plotx = "income", plotPoints=FALSE)
mc3 <- lm(statusquo ~ region * income + sex + age, data= Chile)
summary(mc3)
plotCurves(mc3, modx = "region", plotx = "income")
mc4 <- lm(statusquo ~ income * (age + I(age^2)) + education + sex + age, data=Chile)
summary(mc4)
plotCurves(mc4, modx = "income", plotx = "age")
plotCurves(mc4, modx = "income", plotx = "age", plotPoints=FALSE)
plotCurves(mc4, modx = "age", plotx = "income")
plotCurves(mc4, modx = "income", plotx = "age", plotPoints=FALSE)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|