| fit.plot {NCStats} | R Documentation |
A generic function for constructing a fitted model plot for an lm or nls object. Linear model objects can be of simple linear regression (SLR), indicator variable regression (IVR), one-way ANOVA, or two-way ANOVA models. Non-linear regression models must have a single numerical response variable, at least one continuous explanatory variable and up to two group-factor explanatory variables.
fit.plot(object,...)
## S3 method for class 'lm':
fit.plot(object,...)
## S3 method for class 'SLR':
fit.plot(object,interval=NULL,conf.level=0.95,plot.pts=TRUE,pch=16,
col.pt="black",col.mdl="red",lwd=3,lty=1,lty.ci=2,lty.pi=3,
xlab=names(mdl$model)[2],ylab=names(mdl$model)[1],main=NULL,...)
## S3 method for class 'IVR':
fit.plot(object,interval=NULL,conf.level=0.95,plot.pts=TRUE,
pch=c(16,21,15,22,17,24,c(3:14)),col="rich",lty=c(1:6,1:6),lwd=3,
ylab=names(mdl$model)[1],xlab=names(mdl$model)[2],main=NULL,
legend="topright", ...)
## S3 method for class 'POLY':
fit.plot(object,...)
## S3 method for class 'ONEWAY':
fit.plot(object,xlab=names(object$mf)[2],ylab=names(object$mf)[1],
main=NULL,type="b",pch=16,lty=1,col="black",interval=TRUE,conf.level=0.95,
ci.fun=ci.fp(conf.level),col.ci=col,lty.ci=1,...)
## S3 method for class 'TWOWAY':
fit.plot(object,which,change.order=FALSE,xlab=colnames(object$mf)[ord[1]],
ylab=colnames(object$mf)[1],main=NULL,type="b",
pch=c(16,21,15,22,17,24,c(3:14)),lty=c(1:6,1:6,1:6),col="default",
legend="topright",cex.leg=1,box.lty.leg=0,interval=TRUE,conf.level=0.95,
ci.fun=ci.fp(conf.level),lty.ci=1,...)
## S3 method for class 'nls':
fit.plot(object,d,pch=c(19,1),col=c("black","red"),lwd=2,lty=1,
plot.pts=TRUE,jittered=FALSE,legend=FALSE,
legend.lbls=c("Group 1","Group 2"),ylab=names(mdl$model)[1],
xlab=names(mdl$model)[xpos],main=NULL, ...)
object |
An lm or nls object (i.e., returned from fitting a model with either lm or nls). |
interval |
In SLR or IVR, a string indicating whether to plot confidence (="confidence") or prediction (="prediction") intervals. For a SLR object both can be plotted by using ="both". In one-way or two-way ANOVA, a logical indicating whether the confidence intervals should be plotted or not. |
conf.level |
A decimal numeric indicating the level of confidence to use for confidence and prediction intervals. |
plot.pts |
A logical indicating (TRUE (default)) whether the points are plotted along with the fitted lines. Set to FALSE to plot just the fitted lines. |
pch |
A numeric or vector of numerics indicating what plotting characther codes should be used. In SLR this is the single value to be used for all points. In IVR a vector is used to identify the characters for the levels of the second factor. |
col |
A vector of color names or numbers or the name of a paletted (see details) indicating what color of points and lines to use for the levels of the first factor in an IVR or the second factor in a two-way ANOVA. |
col.pt |
A string used to indicate the color of the plotted points. Used only for SLR objects. |
col.mdl |
A string used to indicate the color of the fitted line. Used only for SLR objects. |
lwd |
A numeric used to indicate the line width of the fitted line. |
lty |
A numeric or vector of numerics used to indicate the type of line used for the fitted line. In SLR this is a single value to be used for the fitted line. In IVR a vector is used to identify the line types for the levels of the second factor. See par. |
lty.ci |
a numeric used to indicate the type of line used for the confidence band lines for SLR objects or interval lines for one-way and two-way ANOVA. For IVR, the confidence band types are controlled by lty. |
lty.pi |
a numeric used to indicate the type of line used for the prediction band lines for SLR objects. For IVR, the prediction band types are controlled by lty. See par. |
xlab |
a string for labelling the x-axis. |
ylab |
a string for labelling the y-axis. |
main |
a string for the main label to the plot. Defaults to the model call. |
legend |
Controls use and placement of the legend. See details. |
type |
The type of graphic to construct in a noe-way and two-way ANOVA. If "b" then points are plotted and lines are used to connect points (DEFAULT). If "p" then only points are used and if "l" then only lines are drawn. |
ci.fun |
A function used to put error bars on the one-way or two-way ANOVA graphs. The default is to use the internal ci.fp function which will place t-distribution based confidence intervals on the graph. The user can provide alternative functions that may plot other types of ‘error bars’. See examples in lineplot.CI function of sciplot package. |
col.ci |
A vector of color names or numbers or the name of a palette (see details) indicating what colors to use for the confidence interval bars in one-way and two-way ANOVAs. |
which |
A character string listing the factor in the two-way ANOVA for which the means should be calculated and plotted. This argument is used to indicate for which factor a main effects plot should be constructed. If left missing then an interaction plot is constructed. |
change.order |
A logical that is used to change the order of the factors in the lm object. This is used to change which factor is plotted on the x-axis and which is used to connect the means when constructing an interaction plot (ignored if which is used). |
cex.leg |
A single numeric values used to represent the character expansion value for the legend. Ignored if legend=FALSE. |
box.lty.leg |
A single numeric values used to indicate the type of line to use for the box around the legend. The default is to not plot a box. |
d |
a data frame containing the variabls used in construction of the nls object. |
jittered |
a logical indicating whether the points should be jittered horizontally. |
legend.lbls |
A vector of strings that will be the labels for the legend in an nls fit.plot graphic. |
... |
Other arguments to be passed to the plot functions. |
This function does not work with a multiple linear regression, indicator variable regression with more than two factors models, ANOVAs other than one-way and two-way, or models with a categorical response variable. In addition, if the linear model contains a factor then the model must be fit with the quantitative explanatory variable first, followed by the factors. This function only works for non-linear models with two or fewer groups.
A legend can be added to the plot in three different ways. First, if legend = TRUE then the R console is suspended until the user places the legend on the graphic by clicking on the graphic at the point where the upper-left corner of the legend should appear. Second, the legend= argument can be set to one of the items in the following list – "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center". In this instance, the legend will be placed on the inside of the plot frame at the given location. Finally, the legend= argument can be set to a vector of length 2 which identifies the plot coordinates for the upper-left corner of where the legend should be placed. A legend will not be drawn if legend = TRUE or legend = NULL. A legend also will not be drawn if there are not multiple groups in the model.
None. However, a fitted-line plot is produced.
Derek H. Ogle, dogle@northland.edu
residual.plot, diag.plot, abline in graphics, interaction.plot in stats, plotmeans in gplots, lineplot.CI in sciplot, plotMeans in Rcmdr, and reg.line in car.
## Linear models example data(Mirex) Mirex$year <- factor(Mirex$year) attach(Mirex) lm1 <- lm(mirex~weight*year*species) fit.plot(lm1) fit.plot(lm1,legend="topleft") lm2 <- lm(mirex~weight*year) fit.plot(lm2,legend="topleft") fit.plot(lm2,legend="topleft",interval="c") lm3 <- lm(mirex~weight+year) fit.plot(lm3,legend="topleft") fit.plot(lm3,legend="topleft",pch=16) lm4 <- lm(mirex~weight) fit.plot(lm4,col.mdl="blue") fit.plot(lm4,interval="cp") lm5 <- lm(mirex~year) fit.plot(lm5) lm6 <- lm(mirex~year*species) fit.plot(lm6,legend="bottomleft") fit.plot(lm6,change.order=TRUE) fit.plot(lm6,change.order=TRUE,col="jet") fit.plot(lm6,which="species") detach(Mirex) ## Non-linear model example data(Ecoli) attach(Ecoli) lr.sv <- list(B1=6,B2=7.2,B3=-1.5) nl1 <- nls(cells~B1/(1+exp(B2+B3*days)),start=lr.sv) fit.plot(nl1,Ecoli,cex.main=0.7,lwd=2) fit.plot(nl1,Ecoli,xlab="Day",ylab="Cellsx10^6/ml",plot.pts=FALSE) detach(Ecoli)