assumptionCheck: Graphics for assessing assumptions of simple linear models.

Description Usage Arguments Details Value Note See Also Examples

View source: R/assumptionCheck.R

Description

A histogram of residuals and a boxplot of residuals by “groups” for ANOVA tests or a residual plot for regression tests is produced. Optionally p-values from the Anderson-Darling test of normality, the outlier test, and Levene's Test for equal variances is shown. The user may also iteratively try power transformations for the response and explanatory variable through arguments in assumptionCheck or a dynamic graphic using slider bars in transChooser.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
assumptionCheck(
  object,
  lambday = 1,
  lambdax = 1,
  shifty = 0,
  shiftx = 0,
  show.stats = TRUE,
  boxplot = TRUE,
  alpha = 0.05,
  col.hist = "gray90"
)

Arguments

object

An lm object or formula depicting a one-way or two-way ANOVA model or a simple linear or indicator variable regression model.

lambday

A numeric value for the power of the transformation of the response variable (see details).

lambdax

A numeric value for the power of the transformation of the explanatory variable (see details).

shifty

A numeric shift value for the transformation of the response variable (see details).

shiftx

A numeric shift value for the transformation of the explanatory variable (see details).

show.stats

A logical indicating if the assumption test p-values should (=TRUE (default)) be printed on the graphics (see details).

boxplot

A logical indicating if the residual plot should be constructed as a boxplot (=TRUE) or as a traditional residual plot (=FALSE). Only effective if a one- or two-way ANOVA model is being examined.

alpha

A numeric used to decide the significance cutoff when choosing the color to print the assumption test p-values. Only has an effect if show.stats=TRUE.

col.hist

A string used to depict the color of bars in the histogram.

Details

These functions only work for one- and two-way ANOVAs and simple and one- or two-way indicator variable regressions.

Each graphic consists of a histogram of raw residuals on the left and a residual plot (constructed with residPlot from FSA package) or a boxplot of residuals by group if boxplot=TRUE in assumptionCheck or the boxplot check box is selected in the gear box when using transChooser. P-values from assumption tests will be shown if show.stats=TRUE in assumptionCheck or if a check box is selected in the gear box when using transChooser. The Anderson-Darling p-values is from adTest), the outlier test p-value is from outlierTest in the car package), and the Levene's Test p-value is from leveneTest in the car package). The lambday and lambdx arguments in assumptionCheck or the slider bar values in the gear box when using transChooser are values for the power transformation of the response and explanatory variables, respectively. Note that a lambda of 0 corresponds to a natural log transformation. Note that lambdax is only used if a regression (SLR or IVR) model is being considered.

The shifty and shiftx arguments are used to provide a constant value to shift the variable being transformed either left (negative value) or right (positive value) along the respective axis. These values are useful if the original data contains negative numbers as the power transformations generally require non-negative values. Note that shiftx is only used if a regression (SLR or IVR) model is being considered.

Value

None. However, a graph, static for assumptionCheck and dynamic for transChooser, is produced.

Note

This function is designed to allow ‘newbie’ students a method that can be used to quickly test assumptions for simple linear models or to interactively choose appropriate transformations for the response or explanatory variables in these models. This function allows students to choose possible transformations based on an intuitive analysis of diagnostic plots, in contrast, to depending on a non-intuitive method such as the Box-Cox method. While this function can be used for research purposes that was not its intent and that is why it is limited to use with only these four simple models.

See Also

leveneTest and outlierTest; adTest; and boxcox in MASS.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
if (require(FSA)) {
data(Mirex)
Mirex$year <- factor(Mirex$year)
Mirex$cyear <- as.character(Mirex$year)

aov1 <- lm(mirex~year,data=Mirex)
assumptionCheck(aov1)
assumptionCheck(aov1,lambday=0)

aov1c <- lm(mirex~cyear,data=Mirex)
assumptionCheck(aov1c)
assumptionCheck(aov1c,lambday=0)

aov2 <- lm(mirex~species*year,data=Mirex)
assumptionCheck(aov2)

slr1 <- lm(mirex~weight,data=Mirex)
assumptionCheck(slr1)
assumptionCheck(slr1,lambday=0)
assumptionCheck(slr1,lambdax=0)

ivr1 <- lm(mirex~weight*year,data=Mirex)
assumptionCheck(ivr1)
}

## Not run: 
# Demonstrates interactive transChooser function
transChooser(aov1)
transChooser(aov2)
transChooser(slr1)
transChooser(ivr1)

## End(Not run)

droglenc/NCStats documentation built on June 5, 2021, 2:06 p.m.