plotly_regtol {tolerance}R Documentation

Plotting Tolerance Intervals for Regressions

Description

Provides interactive tolerance intervals for regression data. More specifically, plotly_regtol presents tolerance bounds for linear regression, nonlinear regression, and nonparametric regression models. In addtion, this updated function is capable of showing tolerance plane for trivariate regression models.

Usage

plotly_regtol(tol.out,
              x,
              new.x = NULL,
              y,
              side = c("two","upper", "lower"),
              rect = FALSE,
              smooth = 4,
              x.lab = NULL,
              x.lab.size = NULL,
              y.lab = NULL,
              y.lab.size = NULL,
              z.lab = NULL,
              z.lab.size = NULL,
              x.tick.size = NULL,
              y.tick.size = NULL,
              z.tick.size = NULL,
              x.col = NULL,
              x.cex = NULL,
              fit.col = NULL,
              fit.lwd = NULL,
              fit.line.type = c("dash","dot","dashdot","solid"),
              fit.opacity = NULL,
              tol.col = NULL,
              tol.lwd = NULL,
              tol.line.type = c("dash","dot","dashdot","solid"),
              tol.opacity = NULL,
              title.position.x = NULL,
              title.position.y = NULL,
              title = NULL,
              title.size = NULL)

Arguments

tol.out

Output from regtol.int, nlregtol.int, npregtol.int or mvregtol.region for regressional data.

x

Data frame for explanatory variables. If there are more than one explanatory variables, columns of x represents regressors.

new.x

An optional data frame in which to look for variables with which to predict. new.x can be used to plot linear regression, nonlinear regression, and multivariate linear regression. new.x has to be a subset of new data in the original output.

y

Data frame for response variable. y is in the formate of a vector.

side

side = "two" produces plots for either the two-sided tolerance intervals or both one-sided tolerance intervals. This will be determined by the output in tol.out. side = "upper" produces plots showing the upper tolerance bounds. side = "lower" produces plots showing the lower tolerance bounds. Note that if the output of in tol.out shows 2-sided tolerance intervals, side = "upper" and side = "lower" still shows both upper AND lower tolerance intervals.

rect

This argument is used for plotting tolerance plane(s) of multivariate regression region. When rect=TRUE the x1-x2 plane is a rectangle.

smooth

The smooth parameter for the x1-x2 plane when rect=TRUE.

x.lab

Label of the x-axis.

x.lab.size

Size of label of the x-axis.

y.lab

Label of the y-axis.

y.lab.size

Size of label of the y-axis.

z.lab

Label of the z-axis.

z.lab.size

Size of label of the z-axis.

x.tick.size

Size of tick marks on the x-axis.

y.tick.size

Size of tick marks on the y-axis.

z.tick.size

Size of tick marks on the z-axis.

x.col

Color of original data points.

x.cex

Size of original data points.

fit.col

Color of fitted line or fitted plane.

fit.lwd

Width of fitted line or fitted plane.

fit.line.type

Type of fitted line or fitted plane.

fit.opacity

Opacity of fitted line or fitted plane.

tol.col

Color of tolerance intervals or tolerance plane.

tol.lwd

Width of tolerance intervals.

tol.line.type

Line type of tolerance intervals

tol.opacity

Opacity of tolerance region.

title.position.x

Horizontal position of the title.

title.position.y

Vertical position of the title.

title

The main title on top of the plot.

title.size

Size of the title.

Value

plotly_regtol returns tolerance intervals for linear regression, nonlinear regression, nonparametric regression, as well as tolerance planes for multivariate (multiple) linear regression models.

References

Montgomery, D. C. (2005), Introduction to Statistical Quality Control, Fifth Edition, John Wiley & Sons, Inc.

See Also

plottol, regtol.int, regtol.int, nlregtol.int, npregtol.int, npregtol.int,mvregtol.region

Examples

## 95%/95% 1-sided linear regression tolerance bounds
## for a sample of size 100.

library(plotly)

set.seed(100)
x <- runif(100, 0, 10)
y <- 20 + 5*x + rnorm(100, 0, 3)
out1 <- regtol.int(reg = lm(y ~ x), new.x = c(3,6,20), new=TRUE ,
                    side = 1, alpha = 0.05, P = 0.95)
plotly_regtol(tol.out = out1 , x=x , y=y , new.x = c(6,20), side = "two" ,
                   fit.line.type = "dash" , tol.line.type = "solid")
########################
set.seed(100)
x1 <- runif(100, 0, 10)
x2 <- rpois(100 , 5)
y <- 20 + 5*x1 + 3*x2 + rnorm(100, 0, 3)
x1.new <- runif(10 , 0 , 10)
x2.new <- rpois(10 , 5)
out2 <- regtol.int(reg = lm(y ~ x1 + x2), new.x = cbind(x1.new , x2.new), new=TRUE,
                    side = 1, alpha = 0.05, P = 0.95)
plotly_regtol(tol.out = out2 , y=y , x=cbind(x1,x2) , new.x = cbind(x1.new , x2.new) , 
                   rect = TRUE , side = "two")
###########################
## 95%/95% 2-sided nonlinear regression tolerance bounds
## for a sample of size 50.
set.seed(100)
x <- runif(50, 5, 45)
f1 <- function(x, b1, b2) b1 + (0.49 - b1)*exp(-b2*(x - 8)) +
  rnorm(50, sd = 0.01)
y <- f1(x, 0.39, 0.11)
formula <- as.formula(y ~ b1 + (0.49 - b1)*exp(-b2*(x - 8)))
out1 <- nlregtol.int(formula = formula,
                      xy.data = data.frame(cbind(y, x)),
                      x.new=c(10,20,50), side = 2,
                      alpha = 0.05, P = 0.95 , new = TRUE)
plotly_regtol(tol.out = out1 , x=x , y=y , new.x = c(20,50) , side = "two",
                   fit.line.type = "dot")
###############

## 95%/95% 1-sided nonparametric regression tolerance bounds
## for a sample of size 50.
set.seed(100)
x <- runif(50, 5, 45)
f1 <- function(x, b1, b2) b1 + (0.49 - b1)*exp(-b2*(x - 8)) + rnorm(50, sd = 0.01)
y <- f1(x, 0.39, 0.11)
y.hat <- loess(y~x)$fit
out1 <- npregtol.int(x = x, y = y, y.hat = y.hat, side = 1,
                      alpha = 0.05, P = 0.95, method = "WILKS" , new = TRUE)
plotly_regtol(tol.out = out1 , x=x , y=y , side = "two" , fit.line.type = "dash")
############
set.seed(100)
x1 <- runif(50, 5, 45)
x2 <- rnorm(50 , 0 , 1)
f1 <- function(x1 , x2 , b1, b2) {b1 + (0.49 - b1)*exp(-b2*(x1 + x2 - 8)) + rnorm(50, sd = 0.01)}
y <- f1(x1 , x2 , 0.39, 0.11)
y.hat <- loess(y~ x1 + x2)$fit
out2 <- npregtol.int(x = cbind(x1 , x2), y = y, y.hat = y.hat, side = 1,
                      alpha = 0.05, P = 0.95, method = "WILKS" , new = TRUE)
plotly_regtol(tol.out = out2 , y=y , x=cbind(x1,x2) , 
                   rect = TRUE , smooth = 100 ,  side = "two")

[Package tolerance version 3.0.0 Index]