Skip to content

Commit ae786d4

Browse files
committed
added argument error.sphere to plot.regvec3d()
1 parent de439eb commit ae786d4

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

R/regvec3d.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ regvec3d.default <- function(x1, x2, y, scale=FALSE, normalize=TRUE,
194194
#' @param x A \dQuote{regvec3d} object
195195
#' @param y Ignored; only included for compatibility with the S3 generic
196196
#' @param dimension Number of dimensions to plot: \code{3} (default) or \code{2}
197-
#' @param col A vector of 4 colors
197+
#' @param col A vector of 5 colors
198198
#' @param col.plane Color of the base plane in a 3D plot or axes in a 2D plot
199199
#' @param cex.lab character expansion applied to vector labels. May be a number or numeric vector corresponding to the the
200200
#' rows of \code{X}, recycled as necessary.
@@ -204,6 +204,8 @@ regvec3d.default <- function(x1, x2, y, scale=FALSE, normalize=TRUE,
204204
#' @param show.hplane If \code{TRUE}, draws the plane defined by \code{y}, \code{yhat} and the origin in the 3D
205205
#' @param show.angles If \code{TRUE}, draw and label the angle between the \code{x1} and \code{x2} and between \code{y} and \code{yhat},
206206
#' corresponding respectively to the correlation between the xs and the multiple correlation
207+
#' @param error.sphere Plot a sphere of radius equal to the length of the residual vector, centered either at the origin (\code{"e"})
208+
#' or at the fitted-values vector (\code{"y.hat"}; the default is \code{"none"}.)
207209
#' @param grid If \code{TRUE}, draws a light grid on the base plane
208210
#' @param add If \code{TRUE}, add to the current plot; otherwise start a new rgl or plot window
209211
#' @param ... Parameters passed down to functions [unused now]
@@ -221,6 +223,7 @@ regvec3d.default <- function(x1, x2, y, scale=FALSE, normalize=TRUE,
221223
#' dunc.reg <- regvec3d(prestige ~ income + education, data=Duncan)
222224
#' plot(dunc.reg)
223225
#' plot(dunc.reg, dimension=2)
226+
#' plot(dunc.reg, error.sphere="e")
224227
#' summary(dunc.reg)
225228
#'
226229
#' # Example showing Simpson's paradox
@@ -231,16 +234,18 @@ regvec3d.default <- function(x1, x2, y, scale=FALSE, normalize=TRUE,
231234
#' }
232235

233236
plot.regvec3d <- function(x, y, dimension=3,
234-
col=c("black", "red", "blue", "brown"), col.plane="gray",
237+
col=c("black", "red", "blue", "brown", "lightgray"), col.plane="gray",
235238
cex.lab=1.2,
236239
show.base=2, show.marginal=FALSE, show.hplane=TRUE, show.angles=TRUE,
240+
error.sphere=c("none", "e", "y.hat"),
237241
grid=FALSE, add=FALSE, ...){
238242

239243
angle <- function(v1, v2) {
240244
r12 <- crossprod(v1, v2)/(len(v1)*len(v2))
241245
acos(r12)*180/pi
242246
}
243-
247+
248+
error.sphere <- match.arg(error.sphere)
244249
vectors <- x$vectors
245250
origin <- c(0,0,0)
246251
abs <- TRUE
@@ -279,7 +284,11 @@ plot.regvec3d <- function(x, y, dimension=3,
279284
arc(vectors[1, ], origin, vectors[2, ], color=col[3])
280285
}
281286
corner(vectors[5, ], origin, vectors[4, ], color=col[4], d=0.05, absolute=abs)
282-
corner(origin, vectors[5, ], vectors[3, ], color=col[4], d=0.05, absolute=abs)
287+
corner(origin, vectors[5, ], vectors[3, ], color=col[4], d=0.05, absolute=abs)
288+
if ("e" == error.sphere) spheres3d(0, 0, 0, radius=len(vectors[4, ]),
289+
color=col[5], alpha=0.1)
290+
else if ("y.hat" == error.sphere) spheres3d(x$vectors[5, ], radius=len(vectors[4, ]),
291+
color=col[5], alpha=0.1)
283292
}
284293
else {
285294
vecs2D <- vectors[c(1,2,5,6,7,8,9), 1:2]

man/plot.regvec3d.Rd

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)