Description Usage Arguments Value See Also Examples
View source: R/RegressionLibs.R
Calculate different error types on the given data and return an object of class data frame ready for usage in different diagnostics plots.
1 | diagnosticData(fit)
|
fit |
an object of class lm that contains the result to fit a linear model regression. |
a data frame object with origin values, fitted values, and differents error types for make some diagnostics plots.
ResidualsFitted, 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 | #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
#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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.