normcheck: Testing for normality plot

View source: R/normcheck.R

normcheckR Documentation

Testing for normality plot

Description

Plots two plots side by side. Firstly it draws a Normal QQ-plot of the residuals, along with a line which has an intercept at the mean of the residuals and a slope equal to the standard deviation of the residuals. If shapiro.wilk = TRUE then, in the top left hand corner of the Q-Q plot, the P-value from the Shapiro-Wilk test for normality is given. Secondly, it draws a histogram of the residuals. A normal distribution is fitted and superimposed over the histogram. NOTE: if you want to leave the x-axis blank in the histogram then, use xlab = c("Theoretical Quantiles", " ") , i.e. leave a space between the quotes. If you don't leave a space, then information will be extracted from x.

Usage

normcheck(x, ...)

## Default S3 method:
normcheck(
  x,
  xlab = c("Theoretical Quantiles", ""),
  ylab = c("Sample Quantiles", ""),
  main = c("", ""),
  col = "light blue",
  bootstrap = FALSE,
  B = 5,
  bpch = 3,
  bcol = "lightgrey",
  shapiro.wilk = FALSE,
  whichPlot = 1:2,
  usePar = TRUE,
  ...
)

## S3 method for class 'lm'
normcheck(
  x,
  xlab = c("Theoretical Quantiles", ""),
  ylab = c("Sample Quantiles", ""),
  main = c("", ""),
  col = "light blue",
  bootstrap = FALSE,
  B = 5,
  bpch = 3,
  bcol = "lightgrey",
  shapiro.wilk = FALSE,
  whichPlot = 1:2,
  usePar = TRUE,
  ...
)

Arguments

x

the residuals from fitting a linear model. Alternatively, a fitted lm object.

...

additional arguments which are passed to both qqnorm and hist

xlab

a title for the x-axis of both the Q-Q plot and the histogram: see title.

ylab

a title for the y-axis of both the Q-Q plot and the histogram: see title.

main

a title for both the Q-Q plot and the histogram: see title.

col

a color for the bars of the histogram.

bootstrap

if TRUE then B samples will be taken from a Normal distribution with the same mean and standard deviation as x. These will be plotted in a lighter colour behind the empirical quantiles so that we can see how much variation we would expect in the Q-Q plot for a sample of the same size from a truly normal distribution.

B

the number of bootstrap samples to take. Five should be sufficient, but hey maybe you want more?

bpch

the plotting symbol used for the bootstrap samples. Legal values are the same as any legal value for pch as defined in par.

bcol

the plotting colour used for the bootstrap samples. Legal values are the same as any legal value for col as defined in par.

shapiro.wilk

if TRUE, then in the top left hand corner of the Q-Q plot, the P-value from the Shapiro-Wilk test for normality is displayed.

whichPlot

legal values are 1, 2, and any pair of the two, i.e. 1:2, 2:1, c(1,2), c(2,1), or even variants of c(1,1) (although I do not know why you would) want to do this. 1:2 is used by default and returns a normal Q-Q plot and a historgram of the residuals in that order. The order of the labels in xlab and ylab assume this order, and will be reordered automatically if the order is anything other than 1:2.

usePar

if TRUE, then this function will set par for the user. If FALSE, then this function assumes par has been set by the user and therefore should not be be over-ridden.

Methods (by class)

  • normcheck(default): Testing for normality plot

  • normcheck(lm): Testing for normality plot

See Also

shapiro.test.

Examples


# An exponential growth curve
e = rnorm(100, 0, 0.1)
x = rnorm(100)
y = exp(5 + 3 * x + e)
fit = lm(y ~ x)
normcheck(fit)

# An exponential growth curve with the correct transformation
fit = lm(log(y) ~ x)
normcheck(fit)

# Same example as above except we use normcheck.default
normcheck(residuals(fit))

# Peruvian Indians data
data(peru.df)
normcheck(lm(BP ~ weight, data = peru.df))


s20x documentation built on Aug. 21, 2023, 5:07 p.m.