###########################################################################
############################# Run this set up code: #######################
###########################################################################
# set seed:
seed=38
# Define training and test files:
qdata.trainfn = system.file("external", "helpexamples","DATATRAIN.csv", package = "ModelMap")
qdata.testfn = system.file("external", "helpexamples","DATATEST.csv", package = "ModelMap")
# Define folder for all output:
folder=getwd()
########## Continuous Response, Categorical Predictors ############
#file name to store model:
MODELfn="RF_BIO_TCandNLCD"
#predictors:
predList=c("TCB","TCG","TCW","NLCD")
#define which predictors are categorical:
predFactor=c("NLCD")
# Response name and type:
response.name="BIO"
response.type="continuous"
#identifier for individual training and test data points
unique.rowname="ID"
###########################################################################
########################### build model: ##################################
###########################################################################
### create model ###
model.obj = model.build( model.type="RF",
qdata.trainfn=qdata.trainfn,
folder=folder,
unique.rowname=unique.rowname,
MODELfn=MODELfn,
predList=predList,
predFactor=predFactor,
response.name=response.name,
response.type=response.type,
seed=seed,
na.action=na.roughfix
)
###########################################################################
###################### make interaction plots: ############################
###########################################################################
#########################
### Perspective Plots ###
#########################
### specify first and third predictors in 'predList (both continuous) ###
model.interaction.plot( model.obj,
x=1,y=3,
main=response.name,
plot.type="persp",
device.type="default")
### specify first and forth predictors in 'predList (one continuous one factored) ###
model.interaction.plot( model.obj,
x=1, y=4,
main=response.name,
plot.type="persp",
device.type="default")
### same as previous example, but specifying predictors by name ##
model.interaction.plot( model.obj,
x="TCB", y="NLCD",
main=response.name,
plot.type="persp",
device.type="default")
###################
### Image Plots ###
###################
### same as previous example, but image plot ###
l <- seq(100,0,length.out=101)
c <- seq(0,100,length.out=101)
col.ramp <- hcl(h = 120, c = c, l = l)
model.interaction.plot( model.obj,
x="TCB", y="NLCD",
main=response.name,
plot.type="image",
device.type="default",
col = col.ramp)
#########################
### 3-way Interaction ###
#########################
### use 'pred.means' argument to fix values of additional predictors ###
### factored 3rd predictor ###
nlcd<-levels(model.obj$predictor.data$NLCD)
for(i in nlcd){
pred.means=list(NLCD=i)
model.interaction.plot( model.obj,
x="TCG", y="TCW",
main=paste("NLCD =",i),
pred.means=pred.means,
z.range=c(0,110),
theta=290,
plot.type="persp",
device.type="default")
}
### continuos 3rd predictor ###
tcb<-seq( min(model.obj$predictor.data$TCB),
max(model.obj$predictor.data$TCB),
length=5)
tcb<-signif(tcb,2)
for(i in tcb){
pred.means=list(TCB=i)
model.interaction.plot( model.obj,
x="TCG", y="TCW",
main=paste("TCB =",i),
pred.means=pred.means,
z.range=c(0,120),
theta=290,
plot.type="persp",
device.type="default")
}
### 4-way Interesting combos ###
tcb=c(1300,2900,3400)
nlcd=c(11,90,95)
for(i in 1:3){
pred.means=list(TCB=tcb[i],NLCD=nlcd[i])
model.interaction.plot( model.obj,
x="TCG", y="TCW",
main=paste("TCB =",tcb[i],"NLCD =",nlcd[i]),
pred.means=pred.means,
z.range=c(0,120),
theta=290,
plot.type="persp",
device.type="default")
}Run the code above in your browser using DataLab