[英]Response surface with persp function in R
I'm using the following code given here .我正在使用此处给出的以下代码。 In R 2.15.2
this code produces the following error:在R 2.15.2
此代码产生以下错误:
could not find function "contour.lm"找不到函数“contour.lm”
What am I missing here?我在这里缺少什么?
ct<-structure(list(Conc = c(50L, 100L, 150L, 50L, 100L, 150L, 50L,
100L, 150L, 100L, 100L, 100L), kGy = c(10L, 10L, 10L, 15L, 15L,
15L, 20L, 20L, 20L, 15L, 15L, 15L), CT.Y. = c(75L, 65L, 51L,
87L, 93L, 89L, 81L, 86L, 78L, 92L, 93L, 92L)), .Names = c("Conc",
"kGy", "CT.Y."), class = "data.frame", row.names = c(NA, -12L))
library(rsm)
ct.rsm<-rsm(CT.Y.~SO(Conc, kGy), data=ct)
persp.lm <-
function (x, form, at, bounds, zlim, zlab, xlabs, col = "white", xlab=xlab,
contours = NULL, hook, atpos = 3, theta = -25, phi = 20,
r = 4, border = NULL, box = TRUE, ticktype = "detailed", ylab,
... )
{
draw.cont.line = function(line) {
if (cont.varycol) {
cont.col = col
if (length(col) > 1)
cont.col = col[cut(c(line$level, dat$zlim), length(col))][1]
}
polygon(trans3d(line$x, line$y, cont.z, transf), col = cont.col,
lwd = cont.lwd)
}
plot.data = contour.lm(x, form, at, bounds, zlim, xlabs,
atpos = atpos, plot.it = FALSE)
transf = list()
if (missing(zlab))
zlab = ""
facet.col = col
cont = !is.null(contours)
if (mode(contours) == "logical")
cont = contours
cont.first = cont
cont.z = cz = plot.data[[1]]$zlim[1]
cont.col = 1
cont.varycol = FALSE
cont.lwd = 1
if (is.character(contours)) {
idx = charmatch(contours, c("top", "bottom", "colors"),
0)
if (idx == 1) {
cont.first = FALSE
cont.z = plot.data[[1]]$zlim[2]
}
else if (idx == 2) {
}
else if (idx == 3) {
cont.varycol = TRUE
if (length(col) < 2)
col = rainbow(40)
}
else cont.col = contours
}
else if (is.list(contours)) {
if (!is.null(contours$z))
cz = contours$z
if (is.numeric(cz))
cont.z = cz
else if (cz == "top") {
cont.first = FALSE
cont.z = plot.data[[1]]$zlim[2]
}
if (!is.null(contours$col))
cont.col = contours$col
if (!is.null(contours$lwd))
cont.lwd = contours$lwd
if (charmatch(cont.col, "colors", 0) == 1) {
cont.varycol = TRUE
if (length(col) < 2)
col = rainbow(40)
}
}
for (i in 1:length(plot.data)) {
dat = plot.data[[i]]
cont.lines = NULL
if (!missing(hook))
if (!is.null(hook$pre.plot))
hook$pre.plot(dat$labs)
if (cont)
cont.lines = contourLines(dat$x, dat$y, dat$z)
if (cont && cont.first) {
transf = persp(dat$x, dat$y, dat$z, zlim = dat$zlim, xlab=ylab,
theta = theta, phi = phi, r = r, col = NA, border = NA,
box = FALSE)
lapply(cont.lines, draw.cont.line)
par(new = TRUE)
}
if (length(col) > 1) {
nrz = nrow(dat$z)
ncz = ncol(dat$z)
zfacet = dat$z[-1, -1] + dat$z[-1, -ncz] + dat$z[-nrz,
-1] + dat$z[-nrz, -ncz]
zfacet = c(zfacet/4, dat$zlim)
facet.col = cut(zfacet, length(col))
facet.col = col[facet.col]
}
transf = persp(dat$x, dat$y, dat$z, xlab = xlab,
zlab = zlab, zlim = dat$zlim, ylab=ylab,
col = facet.col, border = border, box = box, theta = theta,
phi = phi, r = r, ticktype = ticktype)
if (atpos == 3)
title(sub = dat$labs[5])
if (cont && !cont.first)
lapply(cont.lines, draw.cont.line)
if (!missing(hook))
if (!is.null(hook$post.plot))
hook$post.plot(dat$labs)
plot.data[[i]]$transf = transf
}
invisible(plot.data)
}
persp(ct.rsm, Conc ~ kGy, col=rainbow(50), theta=60, xlab="Something",
phi=0, r = 3, d=1, border = NULL, ltheta = -135, lphi = 0
, shade = 0.75, zlab="CT",ylab="Concentration %", col.axis=37, font.lab=2,col.lab=33,
contour=("colors"))
If you look at methods('contour')
, you will see that contour.lm
is not visible.如果您查看methods('contour')
,您会看到contour.lm
不可见。
You can access this by the the :::
syntax.您可以通过:::
语法访问它。 eg.例如。 rsm:::contour.lm
Replacing this in your code makes it work.在您的代码中替换它使其工作。
Note, if persp
were in a package, you could use some variant import
to ensure that contour.lm
was available on search path of the package namespace.注意,如果persp
在一个包中,你可以使用一些变体import
来确保contour.lm
在包命名空间的搜索路径上可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.