DATA IRIS
iris <- read.csv("E:/smt 3/stat/iris.csv",header = TRUE)
head(iris)
## Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm Species
## 1 1 5.1 3.5 1.4 0.2 Iris-setosa
## 2 2 4.9 3.0 1.4 0.2 Iris-setosa
## 3 3 4.7 3.2 1.3 0.2 Iris-setosa
## 4 4 4.6 3.1 1.5 0.2 Iris-setosa
## 5 5 5.0 3.6 1.4 0.2 Iris-setosa
## 6 6 5.4 3.9 1.7 0.4 Iris-setosa
range : nilai minimum dan maksimum
range <- function(x){
uniqx <- unique(x)
uniqx[which.max(tabulate(match(x, uniqx)))]
}
range(iris$SepalLengthCm)
## [1] 5
range(iris$SepalWidthCm)
## [1] 3
range(iris$PetalLengthCm)
## [1] 1.5
range(iris$PetalWidthCm)
## [1] 0.2
modus : nilai yang sering muncul
modus <- function(x){
uniqx <- unique(x)
uniqx[which.max(tabulate(match(x, uniqx)))]
}
modus(iris$SepalLengthCm)
## [1] 5
modus(iris$SepalWidthCm)
## [1] 3
modus(iris$PetalLengthCm)
## [1] 1.5
modus(iris$PetalWidthCm)
## [1] 0.2
rata-rata geometri
mean.geom <- function(x){
exp(mean(log(x)))
}
mean.geom(iris$SepalLengthCm)
## [1] 5.78572
mean.geom(iris$SepalWidthCm)
## [1] 3.023582
mean.geom(iris$PetalLengthCm)
## [1] 3.239757
mean.geom(iris$PetalWidthCm)
## [1] 0.837827
rata-rata harmoni
mean.harm <- function(x){
1/(mean(1/x))
}
mean.harm(iris$SepalLengthCm)
## [1] 5.728905
mean.harm(iris$SepalWidthCm)
## [1] 2.993137
mean.harm(iris$PetalLengthCm)
## [1] 2.696472
mean.harm(iris$PetalWidthCm)
## [1] 0.4866465
nilai skewness dan kurtosis
library(e1071)
skewness(iris$SepalLengthCm)
## [1] 0.3086407
skewness(iris$SepalWidthCm)
## [1] 0.3274013
skewness(iris$PetalLengthCm)
## [1] -0.2689994
skewness(iris$PetalWidthCm)
## [1] -0.102906
library(e1071)
kurtosis(iris$SepalLengthCm)
## [1] -0.6058125
kurtosis(iris$SepalWidthCm)
## [1] 0.1983681
kurtosis(iris$PetalLengthCm)
## [1] -1.416683
kurtosis(iris$PetalWidthCm)
## [1] -1.357368
grafik stem / diagram dahan daun
stem(iris$SepalLengthCm)
##
## The decimal point is 1 digit(s) to the left of the |
##
## 42 | 0
## 44 | 0000
## 46 | 000000
## 48 | 00000000000
## 50 | 0000000000000000000
## 52 | 00000
## 54 | 0000000000000
## 56 | 00000000000000
## 58 | 0000000000
## 60 | 000000000000
## 62 | 0000000000000
## 64 | 000000000000
## 66 | 0000000000
## 68 | 0000000
## 70 | 00
## 72 | 0000
## 74 | 0
## 76 | 00000
## 78 | 0
stem(iris$SepalWidthCm)
##
## The decimal point is 1 digit(s) to the left of the |
##
## 20 | 0
## 21 |
## 22 | 000
## 23 | 0000
## 24 | 000
## 25 | 00000000
## 26 | 00000
## 27 | 000000000
## 28 | 00000000000000
## 29 | 0000000000
## 30 | 00000000000000000000000000
## 31 | 000000000000
## 32 | 0000000000000
## 33 | 000000
## 34 | 000000000000
## 35 | 000000
## 36 | 000
## 37 | 000
## 38 | 000000
## 39 | 00
## 40 | 0
## 41 | 0
## 42 | 0
## 43 |
## 44 | 0
stem(iris$PetalLengthCm)
##
## The decimal point is at the |
##
## 1 | 01223333333444444444444
## 1 | 555555555555556666666777799
## 2 |
## 2 |
## 3 | 033
## 3 | 55678999
## 4 | 000001112222334444
## 4 | 5555555566677777888899999
## 5 | 000011111111223344
## 5 | 55566666677788899
## 6 | 0011134
## 6 | 6779
stem(iris$PetalWidthCm)
##
## The decimal point is 1 digit(s) to the left of the |
##
## 1 | 000000
## 2 | 0000000000000000000000000000
## 3 | 0000000
## 4 | 0000000
## 5 | 0
## 6 | 0
## 7 |
## 8 |
## 9 |
## 10 | 0000000
## 11 | 000
## 12 | 00000
## 13 | 0000000000000
## 14 | 00000000
## 15 | 000000000000
## 16 | 0000
## 17 | 00
## 18 | 000000000000
## 19 | 00000
## 20 | 000000
## 21 | 000000
## 22 | 000
## 23 | 00000000
## 24 | 000
## 25 | 000
grafik boxplot / kotak garis
par(mfrow=c(2,2))
boxplot(iris$SepalLengthCm, main = "sepal length (cm)", xlab = "sepal length (cm)", ylab = "frekuensi",col = "maroon")
boxplot(iris$SepalWidthCm, main = "sepal length (cm)", xlab = "sepal width (cm)", ylab = "frekuensi",col = "pink")
boxplot(iris$PetalLengthCm, main = "sepal length (cm)", xlab = "petal length (cm)", ylab = "frekuensi",col = "lightpink")
boxplot(iris$PetalWidthCm, main = "sepal length (cm)", xlab = "petal width (cm)", ylab = "frekuensi",col = "deeppink")

grafik histogram
par(mfrow=c(2,2))
hist(iris$SepalLengthCm, main = "sepal length (cm)", xlab = "sepal length (cm)", ylab = "frekuensi", col = "maroon")
hist(iris$SepalWidthCm, main = "sepal width cm)", xlab = "sepal width cm)", ylab = "frekuensi", col = "pink")
hist(iris$PetalLengthCm, main = "petal length cm)", xlab = "petal length cm)", ylab = "frekuensi", col = "lightpink")
hist(iris$PetalWidthCm, main = "petal width (cm)", xlab = "petal width (cm)", ylab = "frekuensi", col = "deeppink")

grafik barplot / diagram batang
par(mfrow=c(2,2))
barplot(iris$SepalLengthCm, main = "sepal length (cm)", xlab = "sepal length (cm)", ylab = "frekuensi",col = "maroon")
barplot(iris$SepalWidthCm, main = "sepal width (cm)", xlab = "sepal width (cm)", ylab = "frekuensi",col = "pink")
barplot(iris$PetalLengthCm, main = "petal length (cm)", xlab = "petal length (cm)", ylab = "frekuensi",col = "lightpink")
barplot(iris$PetalWidthCm, main = "petal width (cm)", xlab = "petal width (cm)", ylab = "frekuensi",col = "deeppink")

grafik scatterplot / diagram pencar
par(mfrow=c(2,2))
plot(iris$SepalLengthCm, main = "sepal length (cm)", xlab = "sepal length (cm)", ylab = "frekuensi", col = "maroon")
plot(iris$SepalWidthCm, main = "sepal width (cm)", xlab = "sepal width (cm)", ylab = "frekuensi",col = "pink")
plot(iris$PetalLengthCm, main = "petal length (cm)", xlab = "petal length (cm)", ylab = "frekuensi", col = "lightpink")
plot(iris$PetalWidthCm, main = "petal width (cm)", xlab = "petal width (cm)", ylab = "frekuensi",col = "deeppink")

grafik pieplot / diagram lingkaran
library(plotrix)
lbl <- c("iris-setosa","iris-versicolor","iris-virginica")
pie(table(iris$Species), col = c("pink","lightpink","deeppink"))

pie3D(table(iris$Species), labels = lbl, explode = 0.1, main = "Pie Chart of Species", col = c("pink","lightpink","deeppink"))
