@@ -194,7 +194,7 @@ regvec3d.default <- function(x1, x2, y, scale=FALSE, normalize=TRUE,
194
194
# ' @param x A \dQuote{regvec3d} object
195
195
# ' @param y Ignored; only included for compatibility with the S3 generic
196
196
# ' @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
198
198
# ' @param col.plane Color of the base plane in a 3D plot or axes in a 2D plot
199
199
# ' @param cex.lab character expansion applied to vector labels. May be a number or numeric vector corresponding to the the
200
200
# ' rows of \code{X}, recycled as necessary.
@@ -204,6 +204,8 @@ regvec3d.default <- function(x1, x2, y, scale=FALSE, normalize=TRUE,
204
204
# ' @param show.hplane If \code{TRUE}, draws the plane defined by \code{y}, \code{yhat} and the origin in the 3D
205
205
# ' @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},
206
206
# ' 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"}.)
207
209
# ' @param grid If \code{TRUE}, draws a light grid on the base plane
208
210
# ' @param add If \code{TRUE}, add to the current plot; otherwise start a new rgl or plot window
209
211
# ' @param ... Parameters passed down to functions [unused now]
@@ -221,6 +223,7 @@ regvec3d.default <- function(x1, x2, y, scale=FALSE, normalize=TRUE,
221
223
# ' dunc.reg <- regvec3d(prestige ~ income + education, data=Duncan)
222
224
# ' plot(dunc.reg)
223
225
# ' plot(dunc.reg, dimension=2)
226
+ # ' plot(dunc.reg, error.sphere="e")
224
227
# ' summary(dunc.reg)
225
228
# '
226
229
# ' # Example showing Simpson's paradox
@@ -231,16 +234,18 @@ regvec3d.default <- function(x1, x2, y, scale=FALSE, normalize=TRUE,
231
234
# ' }
232
235
233
236
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" ,
235
238
cex.lab = 1.2 ,
236
239
show.base = 2 , show.marginal = FALSE , show.hplane = TRUE , show.angles = TRUE ,
240
+ error.sphere = c(" none" , " e" , " y.hat" ),
237
241
grid = FALSE , add = FALSE , ... ){
238
242
239
243
angle <- function (v1 , v2 ) {
240
244
r12 <- crossprod(v1 , v2 )/ (len(v1 )* len(v2 ))
241
245
acos(r12 )* 180 / pi
242
246
}
243
-
247
+
248
+ error.sphere <- match.arg(error.sphere )
244
249
vectors <- x $ vectors
245
250
origin <- c(0 ,0 ,0 )
246
251
abs <- TRUE
@@ -279,7 +284,11 @@ plot.regvec3d <- function(x, y, dimension=3,
279
284
arc(vectors [1 , ], origin , vectors [2 , ], color = col [3 ])
280
285
}
281
286
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 )
283
292
}
284
293
else {
285
294
vecs2D <- vectors [c(1 ,2 ,5 ,6 ,7 ,8 ,9 ), 1 : 2 ]
0 commit comments