Description Usage Arguments See Also Examples
View source: R/DiagnosticsPlots.R
Generate a plot of fitted values v/s residuals of a regression model.
1 | ResidualsFitted(diagnostic, dependentVariableName, colours)
|
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. |
colours |
is an optional parameter of class character with a list of colours to use in the plot. The default value for continuos dependent variable is c("darkred", "yellow", "darkgreen") and for categorical dependent variable are the default colours defined by ggplot. |
diagnosticData, StResidualsFitted, NormalQQ, StResidualsLeverange
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.