DensityPlot: Density Plot (Plot)

Description Usage Arguments See Also Examples

View source: R/Plots.R

Description

Generate a density plot for a specific column of the data.

Usage

1

Arguments

data

an object of class data frame with the data.

col

an integer that specify the column that you want for make the plot.

See Also

http://www.rdatamining.com/examples/outlier-detection

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
53
54
55
56
57
58
59
60
#Example 1
#install.packages("Rlof")
library(Rlof) #for outlier detection

iris.x <- iris[,1:4] # These are the independent variables
Species <- iris[,5] # This is the dependent variable

DensityPlot(iris.x,1)


#Example 2
#install.packages("Rlof")
library(Rlof) #Outlier detection library

iris.x <- iris[,1:4] # These are the independent variables
Species <- iris[,5] # This is the dependent variable

outlier.scores <- lof(iris.x, k = 5) #applying outlier detection
outlier.scores <- data.frame(outlier.scores)
DensityPlot(outlier.scores, 1) #Generating a plot of outliers scores


#Example 3
#install.packages("Rlof")
library(Rlof) #Outlier detection library

iris.x <- iris[,1:4] # These are the independent variables
Species <- iris[,5] # This is the dependent variable

outlier.scores <- lof(iris.x, k = c(5:10)) #applying outlier detection
mean <- rowMeans(outlier.scores) #Calculating the mean of every execution
outlier.scores <- data.frame(outlier.scores, mean) #adding mean to data frame
DensityPlot(outlier.scores, ncol(outlier.scores)) #Generating a plot of outliers scores


#Example 4
#install.packages("Rlof")
library(Rlof) #Outlier detection library
library(plyr)
# Getting a 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

outlier.scores <- lof(cars.x, k = c(5:10)) #applying outlier detection
mean <- rowMeans(outlier.scores) #Calculating the mean of every execution
outlier.scores <- data.frame(outlier.scores, mean) #adding mean to data frame
DensityPlot(outlier.scores, ncol(outlier.scores)) #Generating a plot of outliers scores

aux <- outlier.scores[,7]>1.7 #1.7 is the threshold selected
count(aux)[2,2] #Number of outliers found
outliers <- order(outlier.scores[,7], decreasing=T)[1:count(aux)[2,2]] #Getting the values that are on the threshold
Score <- outlier.scores[outliers,7] #Getting outliers scores
outliers <- data.frame(outliers,Score)
names(outliers) <- c("Position","Score")
View(outliers)

auxOutliers <- outlier.scores[-outliers[1:3,1],] #Eliminating the 3 most remote instances!
DensityPlot(auxOutliers, ncol(outlier.scores)) #Generating a plot of outliers scores

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