NormalQQ: Normal-QQ (Plot)

Description Usage Arguments Note See Also Examples

View source: R/DiagnosticsPlots.R

Description

Generate a plot of theoretical quantiles v/s Standarized Residuals of a regression model.

Usage

1
NormalQQ(diagnostic, dependentVariableName)

Arguments

diagnostic

an object of class data frame with differents error types calculated for make the graph.

dependentVariableName

is an optional parameter. It's an string that contains de name of your dependent variable of your regression model.

Note

Part of this code, it's from http://librestats.com/2012/06/11/autoplot-graphical-methods-with-ggplot2/

See Also

diagnosticData, ResidualsFitted, StResidualsFitted, StResidualsLeverange

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#Example 1
iris.x <- iris[,1:3] # These are the independent variables
Petal.Width <- iris[,4] # This is the dependent variable

ir.pca <- prcomp(iris.x, center = TRUE, scale. = TRUE) # Performing prcomp

PCA <- as.data.frame(ir.pca$x)
PC1 <- PCA[,1]
PC2 <- PCA[,2]
PC3 <- PCA[,3]

fit <- lm(Petal.Width ~ PC1 + PC2 + PC3, data = PCA) # Perfoming linear regression

diagnostic <- diagnosticData(fit) # Generating data for differents plots
ResidualsFitted(diagnostic, "Petal Width") # Generating Residuals v/s Fitted Values plot
StResidualsFitted(diagnostic, "Petal Width") #Generating Standarized Residuals v/s Fitted Values plot
NormalQQ(diagnostic, "Petal Width") # Generating Normal-QQ plot
StResidualsLeverange(diagnostic, "Petal Width") # Generating Leverange v/s Standarized Residuals plot

# Plots with a different colours palette
myPalette <- c("darkolivegreen4", "goldenrod1", "dodgerblue4")
ResidualsFitted(diagnostic, "Petal Width", colours = myPalette) # Generating Residuals v/s Fitted Values plot
StResidualsFitted(diagnostic, "Petal Width", colours = myPalette) #Generating Standarized Residuals v/s Fitted Values plot
StResidualsLeverange(diagnostic, "Petal Width",colours = myPalette) # Generating Leverange v/s Standarized Residuals plot


#Example 2
# Getting a clean data set (without missing values)
cars <- read.csv("https://dl.dropboxusercontent.com/u/12599702/autosclean.csv", sep = ";", dec = ",")
cars.x <- cars[,1:16] # These are the independent variables
cars.y <- cars[,17] # This is the dependent variable

cars.pca <- prcomp(cars.x, center = TRUE, scale. = TRUE)

PCA <- as.data.frame(cars.pca$x)
PC1 <- PCA[,1]
PC2 <- PCA[,2]
PC3 <- PCA[,3]

fit <- lm(cars.y ~ PC1 + PC2 + PC3, data = PCA) # Perfoming linear regression

diagnostic <- diagnosticData(fit) # Generating data for differents plots
ResidualsFitted(diagnostic, "Price") # Generating Residuals v/s Fitted Values plot
StResidualsFitted(diagnostic, "Price") #Generating Standarized Residuals v/s Fitted Values plot
NormalQQ(diagnostic, "Price") # Generating Normal-QQ plot
StResidualsLeverange(diagnostic, "Price") # Generating Leverange v/s Standarized Residuals plot

# Plots with a different colours palette
myPalette <- c("darkolivegreen4", "goldenrod1", "dodgerblue4")
ResidualsFitted(diagnostic, "Price", colours = myPalette) # Generating Residuals v/s Fitted Values plot
StResidualsFitted(diagnostic, "Price", colours = myPalette) #Generating Standarized Residuals v/s Fitted Values plot
StResidualsLeverange(diagnostic, "Price",colours = myPalette) # Generating Leverange v/s Standarized Residuals plot

mariytu/RegressionLibs documentation built on May 21, 2019, 11:47 a.m.