R/minitabRes.R

#' minitabRes function
#'
#'This function allows you to visualize the 4-in-1 residual plot function from Minitab. Input a list for your x value, a list for your value, an optional custom title for your graph, and that's it!
#'@param x A list of values that will serve as your explanatory "x" variable.
#'@param y A list of values that will serve as your dependent "y" variables.
#'@param Title This is the title of your set of graphs, defaults to "Residual Plots".
#'
#'@keywords minitabRes
#'@export
minitabRes <- function(x,y,Title="Residual Plots"){
myResiduals <- rstandard(lm(y~x))
oldPar <- par() #Store graphical parameters for a 'reset' later
par(oma=c(0,0,2,0), mfrow=c(2,2)) #Change the outer plot margins to make room for a primary title and change the plotting window to allow four plots (2x2)
minitabQQ(x,y) #Plot the normal probability plot
plot(lm(y~x)$fitted.values, myResiduals, pch=16, col="red", cex=1.2, xlab= "Fitted Value", ylab="Residual", main="Versus Fits"); abline(h=0) #Plot Fitted vs Residual values and add a horizontal line at the mean
hist(myResiduals, breaks=10, col="gray", main="Histogram", xlab="Residual") #Plot historgram of residual values
plot(seq(1,length(myResiduals)), myResiduals, pch=16, col="red", cex=1.2, xlab="Observation Order", ylab="Residual", main="Versus Order") #Plot residuals by observational order
lines(seq(1,length(myResiduals)), myResiduals, col="blue"); abline(h=0) #Add a horizontal mean line at 0 and a line connecting each point
title(Title, line = 0, outer = TRUE) #Add a primary plot title
par(oldPar) #Reset the graphical parameters to what they were original
}
18kimn/yalestats documentation built on May 9, 2019, 2:17 a.m.