Learn R Programming

forestFloor (version 1.5)

show3d_new: make 3d-plot of forestFloor topology

Description

2 features features(horizontal XY-plane) and one combined feature contribution (vertical Z-axis). Surface response layer will be estimated(gaussian-kNN by kknn package) and plotted alongside the datapoints. 3D grphic device is rgl.

Usage

show3d_new(ff,
           Xi  = 1:2,
           FCi = NULL,
           col = "#12345678",    
           sortByImportance = TRUE,
           surface=TRUE,   
           combineFC = sum,  
           zoom=1.2,       
           grid.lines=30,  
           limit=3, 
           kknnGrid.args = alist(),  
           plot.rgl.args = alist(),  
           surf.rgl.args = alist()   
           )

Arguments

ff
forestFloor" class object
Xi
integer vector of length 2 indices of feature columns
FCi
integer vector of length 1 to p variables indices of feature contributions columns
col
colour vector points colour or colour palette, can also be passed as promise in plot.rgl.args
sortByImportance
booleen should indices count 'variable importance' order or matrix/data.frame order
surface
should a surface be plotted also
combineFC
how should feature contributions be combined
zoom
#grid can be expanded in all directions by a factor ,zoom
grid.lines
#how many grid lines should be used
limit
#sizing of grid does not concider outliers, outside limit of e.g. 3 sd deviations univariately
kknnGrid.args
argument list, any possiple arguments to kknn{kknn} These default wrapper arguments can hereby be overwritten: wrapper = alist( formula=fc~., # do not change train=Data, # do not change k=k, # integer < n_observations. k>10
plot.rgl.args
pass argument to rgl::plot3d, can override any argument of this wrapper, defines plotting space and plot points. See plot3d for documentation of graphical arguments. wrapper_arg = alist( x=xaxis, #do not change, x coordinates y=yaxis, #do not
surf.rgl.args
wrapper_arg = alist( x=unique(grid[,2]), #do not change, values of x-axis y=unique(grid[,3]), #do not change, values of y-axis z=grid[,1], #do not change, response surface values add=TRUE, #do not change, surface added to plot

Value

  • no value

Details

show3d plot one or more combined feature contributions in the context of two features with points representing each data point. The input object must be of forestFloor class, and should at least contain $X the data.frame of training data, $FCmatrix the feature contributions matrix.

This wrapper function will first plot points. Any graphical argument of the 3D plotting scene can be forwarded through plot.rgl.args, see plot3d{rgl}. The transparency of points could e.g. be lowered from 0.4 to 0.1 and the size increased by using plot.rgl.args = alist(alpha=0.1,size=5) Secondly, a grid response surface layer will be estimated(gaussian-kNN), on basis of selected features and feature contributions. Any argument can passed to kknn{kknn} by kknnGrid.args, e.g. kknnGrid.args = alist(k=5, kernel="triangular") Thirdly the surface grid is plotted. Any argument can be forwarded to persp3d{rgl} through surf.rgl.args. The surface layer could be coloured and made more transparent by passing surf.rgl.args = alist(alpha=0.2, col=c("red","green","blue")). Notice some graphical settings, should as axis labels(xlab) must be defined by plot.rgl.args. policy of merging user arguments with wrapper arguments is handled by append.overwrite.alists{forestFloor}

Examples

Run this code
rm(list=ls())
library(forestFloor)
#simulate data
obs=2500
vars = 6 

X = data.frame(replicate(vars,rnorm(obs)))
Y = with(X, X1^2 + sin(X2*pi) + 2 * X3 * X4 + 1 * rnorm(obs))


#grow a forest, remeber to include inbag
rfo=randomForest(X,Y,keep.inbag = TRUE,sampsize=1500,ntree=500)

#compute topology
ff = forestFloor(rfo,X)


#print forestFloor
print(ff) 

#plot partial functions of most important variables first
plot(ff) 

#Non interacting functions are well displayed, whereas X3 and X4 are not
#by applying different colourgradient, interactions reveal themself 
Col = fcol(ff,3)
plot(ff,col=Col) 

#in 3D the interaction between X3 and X reveals itself completely
show3d_new(ff,3:4,col=Col,plot.rgl=list(size=5)) 

#although no interaction, a joined additive effect of X1 and X2
Col = fcol(ff,1:2,X.m=FALSE,RGB=TRUE) #colour by FC-component FC1 and FC2 summed
plot(ff,col=Col) 
show3d_new(ff,1:2,col=Col,plot.rgl=list(size=5)) 

#...or two-way gradient is formed from FC-component X1 and X2.
Col = fcol(ff,1:2,X.matrix=TRUE,alpha=0.8) 
plot(ff,col=Col) 
show3d_new(ff,1:2,col=Col,plot.rgl=list(size=5))

Run the code above in your browser using DataLab