ciplot: Confidence Interval Plot

Description Usage Arguments Warning Author(s) References See Also Examples

View source: R/ciplot.R

Description

given two numeric vectors of equal length, plot a scatter plot of the data, the regression line, and a confidence interval for the mean of a new observation or the prediction interval for a single new observation.

Usage

1
2
3
ciplot(x, y, x0 = NULL, int = c("p","c"), level = 0.95, 
relationship = c("linear","quadratic","cubic","sqrt","exponential","reciprocal","log"), 
show.range = TRUE, user.xlim = NULL, user.ylim = NULL)

Arguments

x

a numeric vector of length > 3

y

a numeric vector of length > 3 (equal in length to x)

x0

the x value at which you wish to make a prediction (NULL by default. If left blank, the plot will not show a prediction at a particular x value.)

int

interval type. "prediction" by default (can be abbreviated), which will plot the prediction interval for a single new observation. If specified with "confidence" (can be abbreviated), it will show the confidence interval for the mean value of a new observation.

level

the confidence level at which you wish to predict. 0.95 by default. If you wish to specify a confidence level, it must be a numerical value greater than 0 and less than 1.

relationship

the type of relationship that the two vectors share. "linear" by default. May specify a different type of relationship with "quadratic" (may be abbreviated to "quad"), "cubic", "sqrt", "exponential" (may be abbreviated to "exp"), "reciprocal" (may be abbreviated to "recip"), or "logarithmic" (may be abbreviated to "log"). Specifying a different type of relationship will change the shape of the regression line.

show.range

logical. If TRUE (the default), dotted red lines will show the confidence or prediction interval along the entire plot. If FALSE, it will only show the confidence/prediction interval at a specified x value (if x0 is set).

user.xlim

the interval of x values the user wishes to display in the plot. If left unspecified, it will be NULL and the default x limits will be plotted (which will be the entire range of x, including x0).

user.ylim

the interval of y values the user wishes to display in the plot. If left unspecified, it will be NULL and the default y limits will be plotted (which will be the entire range of y, including the predicted y value at x0).

Warning

If x0 is outside the domain of x, ciplot will extrapolate the data and predict a value of yhat for the given x0. This may be dangerous, depending on how your data behaves outside the existing domain.

Author(s)

Jonathan Schwartz

References

Montgomery, D. C., Peck, E. A., Vining, G. G. (2013), Introduction to Linear Regression Analysis, Hoboken, NJ: John Wiley & Sons, Inc.

See Also

plot, lm, predict

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
##predicting the mean petal width of an iris whose petal length is 2.5
ciplot(iris$Petal.Length,iris$Petal.Width,x0=2.5,int="conf")

##predicting a single new observation of the petal width of an iris whose petal length is 2.5
ciplot(iris$Petal.Length,iris$Petal.Width,x0=2.5,int="pred")

##extrapolating the data to predict the mean of the width of an iris's petal whose petal length is 8
ciplot(iris$Petal.Length,iris$Petal.Width,x0=8,int="conf")

##zooming in to the previous graph and removing the dotted red lines
ciplot(iris$Petal.Length,iris$Petal.Width,x0=8,int="conf",show.range=FALSE,
user.xlim=c(7.5,8.5),user.ylim=c(2.6,3.2))

handyplots documentation built on May 2, 2019, 6:12 a.m.