plot.mixreg {mixreg} | R Documentation |
Plots the fitted regression lines for one or two mixtures of
regression models as fitted by mixreg()
(or possibly by
visualFit()
).
## S3 method for class 'mixreg' plot(x, y, cMeth=c("none","distance","prob"), ptcol="black",col=NULL,col2=NULL,lty=NULL,lty2=NULL, add=FALSE, warn=TRUE, modnames=NULL, legPos = "topleft", ...)
x |
An object of class |
y |
If supplied it must be an object of class |
cMeth |
Text string specifying the “classification method”.
If |
ptcol |
Scalar specfying the colour in which the data points are plotted.
Ignored unless |
col |
Vector specifying the colours in which the fitted lines, corresponding
to each of the components, should be plotted. Defaults to |
col2 |
Like |
lty |
Vector specifying the line types used for plotting the fitted lines
corresponding to each of the components. Defaults to |
lty2 |
Like |
add |
For internal use only. |
warn |
Logical scalar; should a warning be issued if the data for the
plot being added (those corresponding to argument |
modnames |
Character vector, of length 2, of “model names”. Used by
|
legPos |
A list with entries |
... |
Optional extra arguments for |
If both x
and y
models are both specified, or
if cMeth
is "none"
, then no value is returned.
Otherwise the value is the data
component of the
x
argument of this function, augmented by an extra
column groups
. This column is a factor that specifies
the component to which each point has been assigned. This data
frame also has an attribute "cMeth"
, the value of the
cMeth
argument.
Superimposing a plot of one fitted mixture of regressions model
upon that of another such model really makes sense only if the
same underlying data set is involved. The code checks whether the
data sets appear to be the same, and if not, issues a warning when
warn
is TRUE
.
Note that only the data points corresponding to the first model
(i.e. that corresponding to argument x
) are plotted. The
resulting graphic would be too cluttered otherwise, and anyway,
as was said initially, the plot doesn't really make sense if
different data sets are involved.
Rolf Turner r.turner@auckland.ac.nz
plot.cband()
, plot.mixresid()
,
qqMix()
,
thStrt <- list( list(beta=c(26.07,48808),sigsq=1.1573,lambda=0.33333333), list(beta=c(23.48,32387),sigsq=1.8730,lambda=0.33333333), list(beta=c(-0.0597,20760),sigsq=0.2478,lambda=0.33333333) ) kfit <- mixreg(y ~ x,ncomp=3,data=kilnAoneOut,thetaStart=thStrt) plot(kfit,pch=8,col=c("red","green","blue","black")) plot(kfit,pch=8,col=c("green","blue","black"),cMeth="d") plot(kfit,pch=8,col=c("green","blue","black"),cMeth="p") afit <- mixreg(plntsInf ~ aphRel,data=aphids,ncomp=2) plot(afit,cMeth="p",col=c("blue","red"),pch=20) # Separates the points into two groups incredibly clearly! npfit <- mixreg(plntsInf ~ 1, data=aphids,ncomp=2) plot(npfit,cMeth="p",col=c("blue","red"),pch=20) ## Not run: vfit <- visualFit(plntsInf ~ aphRel,data=aphids,ncomp=2) afit <- mixreg(plntsInf ~ aphRel,data=aphids,thetaStart=vfit$theat) plot(vfit,afit,col=c("black","red"),col2=c("blue","green"), modnames=c("Visual","Analytic")) bfit <- mixreg(plntsInf ~ aphRel,data=aphids) plot(afit,bfit,col=c("black","red"),col2=c("blue","green"), modnames=c("Visual start","Random start")) # Results from visual start and random start look identical. ## End(Not run) fit.real <- mixreg(plntsInf ~ aphRel,data=aphids,ncomp=2) simDat <- rmixreg(fit.real) fit.sim <- mixreg(plntsInf ~ aphRel,data=simDat,ncomp=2) plot(fit.real,fit.sim,col=c("black","red"),col2=c("blue","green"), lty=1:2,lty2=3:4,warn=FALSE,legPos="topleft",cMeth="p",pch=20, modnames=c("Real data","Simulated data"), main="Real data points plotted") # We set warn=FALSE since we are well aware that the data sets differ. plot(fit.sim,fit.real,col2=c("black","red"),col=c("blue","green"), lty2=1:2,lty=3:4,warn=FALSE,legPos="topleft",cMeth="p",pch=20, modnames=c("Simulated data","Real data"), main="Simuated data points plotted.")