ModelPlot: This function makes contour plots of a user-supplied model in...

Description Usage Arguments Author(s) References Examples

View source: R/ModelPLot.R

Description

This function makes contour plots in the simplex mixture space. It also can draw constraint lines and zoom in on pseudo component region.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
ModelPlot(model=NULL,user.func = NULL, dimensions = list(x1=NULL,x2=NULL,x3=NULL),
          slice=NULL,lims=rep(0,6), constraints = FALSE,
          constraint.pars = list(lty=2,lwd=2),
          contour = FALSE, contour.pars = list(lwd=0.5,cex.lab=1.3),
          cuts = 10,at = NULL, res=300, pseudo=FALSE, 
          fill=FALSE, color.palette = heat.colors, 
          main=NULL, axislabs=c("Fraction X1","Fraction X2","Fraction X3"),
          axislab.pars = list(),
          axislab.offset=0,
          cornerlabs = c("X1", "X2", "X3"),
          cornerlab.pars = list(),
          grid=TRUE, grid.pars = list(col='darkgrey',lty=3,lwd=0.5),
          colorkey = FALSE,
          labels=TRUE, label.style="align", ...)

Arguments

model

an lm object, MixModel object, or any other model object that is compatible with the predict function, which is the mixture model to be plotted.

user.func

function supplied by the user that takes as arguments a dataframe called 'grid' and returns the predictions. This argument has been deprecated in favor of the model argument. Typically, this will be a wrapper function for predict() (e.g. predict(model,newdata=grid)). Additional arguments for user.func can be passed using the ellipsis argument for ModelPlot. Overrides model argument if both are specified.

dimensions

list argument that specifies the mixture variables to be plotted on the ternary plot. Values must correspond to variable names from the user-supplied model.

slice

list argument that specifies the value of fixed mixture components.

lims

vector of lower and upper constraints for ternary plot components (TopLower, TopUpper, LeftLower, LeftUpper, RightLower, RightUpper).

constraints

if TRUE constraints found in lims will be added to the graph.

constraint.pars

list of graphical parameters controlling the appearance of the constraint lines.

contour

if TRUE contour lines will be added to the graph.

contour.pars

list of graphical parameters controlling the appearance of the contour lines.

cuts

number of breaks between levels (used for contours if 'at' not specified).

at

list of contour levels (e.g. at=c(1,3,5,10) will draw contours at those heights). Overrides cuts argument.

res

resolution of the grid. Corresponds to number equally spaced values along the baseline of the simplex.

pseudo

if TRUE uses pseudo components to zoom in on constrained region. Will create the smallest equilateral triangle that still contains the whole constrained region.

fill

if TRUE regions between contour lines will be colored.

color.palette

is the color palette to use.

main

character value for main title or list containing character value and graphical parameters (e.g. main=list("main title",cex=2)).

axislabs

character vector of axis labels for ternary components.

axislab.pars

list of graphical parameters controlling the appearance of the axislabels.

axislab.offset

numeric value that creates or eliminates space between the angled axislabels and the tickmarks. Prevents axis labels from overlapping with tickmarks. Typically, absolute value would not exceed 0.05.

cornerlabs

character vector of corner labels for x1, x2 and x3 vertices.

cornerlab.pars

list of graphical parameters controlling the appearance of the axis labels.

grid

logical argument. If true, adds gridlines to the ternary plot.

grid.pars

list of graphical parameters controlling the appearance of the gridlines.

colorkey

logical or list of parameters. See levelplot documentation for more details.

labels

logical argument. If true, labels contour lines.

label.style

controls placement of contour labels. Choose from "mixed","flat", or "align." See panel.levelplot documentation for more details.

...

additional arguments passed to user.func

Author(s)

Cameron Willden [email protected]

References

1. Cornell, J. A. Experiments with Mixtures: Models and Analysis of Mixture Data, John Wiley & Sons, New York, third edition, 2002.

2. See R Ternary Level Plot Function http://www.siftp.net/index.shtml

3. "John Lawson, Cameron Willden (2016).", "Mixture Experiments in R Using mixexp.", "Journal of Statistical Software, Code Snippets, 72(2), 1-20.", "doi:10.18637/jss.v072.c02"

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Cornell's (2002) Yarn elongation
x1<-c(1,1,.5,.5,.5,0,0,0,0,0,0,0,.5,.5,.5)
x2<-c(0,0,.5,.5,.5,1,1,.5,.5,.5,0,0,0,0,0)
x3<-c(0,0,0,0,0,0,0,.5,.5,.5,1,1,.5,.5,.5)
y<-c(11,12.4,15,14.8,16.1,8.8,10,10,9.7,11.8,16.8,16,17.7,16.4,16.6)
elong<-data.frame(x1,x2,x3,y)
testQ<-lm(y~-1+x1+x2+x3+x1:x2+x1:x3+x2:x3,data=elong)
ModelPlot(model = testQ,dimensions = list(x1="x1",x2="x2",x3="x3"), 
           main="Thread Elongation",constraints=FALSE,contour=TRUE,
           at=c(12, 13, 14, 15, 16, 17),fill=FALSE,
           axislabs=c("X1", "X2", "X3"),
           cornerlabs = c("X1", "X2", "X3"),pseudo=FALSE)
           

# Cornells famous fish patty experiment 
data(fishp)
fishmod2<-MixModel(fishp, "y", mixcomps=c("x1","x2","x3"),model=5,procvars=c("z1","z2","z3"))
ModelPlot(fishmod2,dimensions = list(x1="x1",x2="x2",x3="x3"), 
          slice = list(process.vars=c(z1=-1, z2=-1, z3=-1)), main="z1=-1, z2=-1, z3=-1",
          constraints=FALSE,contour=TRUE,cuts=10,fill=FALSE,
          axislabs=c("Fraction X1","Fraction X2","Fraction X3"),
          cornerlabs = c("X1", "X2", "X3"),pseudo=FALSE)
          
          
#### Kowalski Cornell and Vining Simplified model on data from Gallant et. al. (2008)
data(Burn)
testBNM<-MixModel(Burn,"y",mixcomps=c("Course","Fine","Binder"),model=6,procvars=c("z"))
ModelPlot(testBNM,dimensions = list(x1="Course",x2="Fine",x3="Binder"), 
          slice = list(process.vars=c(z=1)), lims=c(.403,.704,.166,.467,.130,.431), main="z=1",
          constraints=TRUE,contour=TRUE,cuts=5,fill=FALSE,
          axislabs=c("Fraction Course","Fraction Fine","Fraction Binder"),
          cornerlabs = c("Course", "Fine", "Binder"),pseudo=TRUE)

ModelPlot(testBNM,dimensions = list(x1="Course",x2="Fine",x3="Binder"), 
          slice = list(process.vars=c(z=-1)),  lims=c(.403,.704,.166,.467,.130,.431),main="z=-1",
          constraints=TRUE,contour=TRUE,cuts=5,fill=FALSE,
          axislabs=c("Fraction Course","Fraction Fine","Fraction Binder"),
          cornerlabs = c("Course", "Fine", "Binder"),pseudo=TRUE)

          

Example output

Loading required package: gdata
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to locate valid perl interpreter
gdata: 
gdata: read.xls() will be unable to read Excel XLS and XLSX files
gdata: unless the 'perl=' argument is used to specify the location of a
gdata: valid perl intrpreter.
gdata: 
gdata: (To avoid display of this message in the future, please ensure
gdata: perl is installed and available on the executable search path.)
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLX' (Excel 97-2004) files.

gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLSX' (Excel 2007+) files.

gdata: Run the function 'installXLSXsupport()'
gdata: to automatically download and install the perl
gdata: libaries needed to support Excel XLS and XLSX formats.

Attaching package: 'gdata'

The following object is masked from 'package:stats':

    nobs

The following object is masked from 'package:utils':

    object.size

The following object is masked from 'package:base':

    startsWith

Loading required package: lattice
Loading required package: grid
Loading required package: daewr
     
            coefficients    Std.err     t.value         Prob
x1           2.864462103 0.04234994 67.63793082 0.000000e+00
x2           1.074461379 0.04234991 25.37104411 4.187761e-13
x3           2.001961379 0.04234991 47.27191823 0.000000e+00
x2:x1       -0.974225170 0.19467104 -5.00446886 1.929102e-04
x3:x1       -0.834225170 0.19467104 -4.28530694 7.547026e-04
x2:x3        0.355776277 0.19467079  1.82757916 8.900087e-02
x1:z1        0.487320097 0.04234991 11.50699305 1.599576e-08
x1:z2        0.708569736 0.04234991 16.73131699 1.189853e-10
x1:z3       -0.087774559 0.04234991 -2.07260329 5.715245e-02
x2:z1        0.177320097 0.04234991  4.18702438 9.133006e-04
x2:z2        0.256069736 0.04234991  6.04652401 3.005020e-05
x2:z3       -0.080274559 0.04234991 -1.89550728 7.886075e-02
x3:z1        0.249820097 0.04234991  5.89895253 3.875071e-05
x3:z2        0.403569736 0.04234991  9.52941233 1.691405e-07
x3:z3        0.009725441 0.04234991  0.22964492 8.216889e-01
x2:x1:z1    -0.801401859 0.19467081 -4.11670278 1.047416e-03
x2:x1:z2    -0.661396432 0.19467081 -3.39751212 4.334288e-03
x2:x1:z3     0.105491309 0.19467081  0.54189588 5.964101e-01
x3:x1:z1    -0.531401859 0.19467081 -2.72974599 1.627937e-02
x3:x1:z2    -0.121396432 0.19467081 -0.62359854 5.429185e-01
x3:x1:z3    -0.019508691 0.19467081 -0.10021374 9.215956e-01
x2:x3:z1    -0.131401859 0.19467081 -0.67499519 5.106734e-01
x2:x3:z2    -0.006396432 0.19467081 -0.03285768 9.742519e-01
x2:x3:z3    -0.184508691 0.19467081 -0.94779845 3.593062e-01
x1:z1:z2     0.060596713 0.04234991  1.43085819 1.744122e-01
x1:z1:z3    -0.045710246 0.04234991 -1.07934700 2.986780e-01
x1:z2:z3     0.090539990 0.04234991  2.13790287 5.064447e-02
x2:z1:z2    -0.031903287 0.04234991 -0.75332601 4.637352e-01
x2:z1:z3    -0.043210246 0.04234991 -1.02031500 3.248879e-01
x2:z2:z3    -0.029460010 0.04234991 -0.69563339 4.980440e-01
x3:z1:z2    -0.004403287 0.04234991 -0.10397395 9.186648e-01
x3:z1:z3     0.166789754 0.04234991  3.93837346 1.485311e-03
x3:z2:z3    -0.049460010 0.04234991 -1.16788943 2.623566e-01
x2:x1:z1:z2  0.028067862 0.19467081  0.14418115 8.874123e-01
x2:x1:z1:z3  0.104204067 0.19467081  0.53528348 6.008539e-01
x2:x1:z2:z3 -0.095797660 0.19467081 -0.49210080 6.302747e-01
x3:x1:z1:z2  0.028067862 0.19467081  0.14418115 8.874123e-01
x3:x1:z1:z3 -0.300795933 0.19467081 -1.54515171 1.446097e-01
x3:x1:z2:z3 -0.340797660 0.19467081 -1.75063566 1.018801e-01
x2:x3:z1:z2  0.313067862 0.19467081  1.60819110 1.301045e-01
x2:x3:z1:z3 -0.285795933 0.19467081 -1.46809855 1.641840e-01
x2:x3:z2:z3  0.209202340 0.19467081  1.07464669 3.007059e-01
     
Residual standard error:  0.1202399  on  14 degrees of freedom 
Corrected Multiple R-squared:  0.9932783[1] "Warning, when using Model 6 the design in the process variables allow fitting the full quadratic model"
     
              coefficients    Std.err    t.value         Prob
Course          1.17881082 0.15738887  7.4897981 0.0006704825
Fine            1.56618342 0.51991903  3.0123602 0.0296751442
Binder          2.80456699 1.44532548  1.9404397 0.1100088693
I(z^2)         -0.02764282 0.02446989 -1.1296666 0.3098790251
Course:Fine    -1.25308532 1.04869291 -1.1949021 0.2857076085
Course:Binder  -6.40963854 2.32653100 -2.7550196 0.0400707338
Fine:Binder    -3.85811780 2.21515437 -1.7416925 0.1420348213
Course:z       -0.06320411 0.04478833 -1.4111739 0.2172798030
Fine:z         -0.05809344 0.06497273 -0.8941204 0.4122240709
Binder:z        0.25072069 0.18974439  1.3213603 0.2436142528
     
Residual standard error:  0.02236335  on  5 degrees of freedom 
Corrected Multiple R-squared:  0.961453

mixexp documentation built on May 29, 2017, 7:09 p.m.