You are on page 1of 8

Bayu Widodo, ST MT

Latihan Lab Komputasi Statistik

Probabilitas &
Statsitika

Prodi Manajemen Informatika, Sekolah Vokasi IPB


Covid-Bogor, September 2020
BAB 5 | Visualisasi Data

“R is a scripting language for statistical data manipulation and analysis. It was


inspired by, and is mostly compatible with, the statistical language S developed by
AT&T.The name S, obviously standing for statistics, was an allusion to another
programming language developed at AT&T with a one- letter name, C. S later was
sold to a small firm, which added a GUI interface and named the result S-Plus.

Tugas Lab-1 :
> eyecol<-c(1,2,1,2,2,2,3,3,1,4,2,2,2,3,1,4,3,2,1,1,1)
> table(eyecol)
> eyecol<-factor(eyecol, \
labels=c("blue","grey","brown","green"))
> table(eyecol)
> eyecol<-c(1,2,1,2,2,2,3,3,1,4,2,2,2,3,1)
> sex <- c(1,1,1,2,1,2,1,1,1,2,1,1,1,2,2)
> table(sex,eyecol)
> prop.table(table(sex,eyecol),1) # row
> prop.table(table(sex,eyecol),2) # column
> proporsi1 <- prop.table(table(sex,eyecol),1)
> proporsi1
> proporsi1 <- round(proporsi1, digits=2)
> proporsi1
> addmargins(proporsi1)
> addmargins(proporsi1,1)
> addmargins(proporsi1,2)

83
Probabilitas dan Bab 5. Visualisasi Data
Statistika
Tugas Lab-2 :

> weight <- c(56,67,65,78,49,87,55,63,70,72,79,52,60,78,90)


> gender <- c(1,1,1,2,1,2,1,1,1,2,1,1,1,2,2)
> tapply(weight,gender,mean)
> tapply(weight,gender,summary)

Tugas Lab-3 :

> mtcars
> table(mtcars$carb)
> table(mtcars$gear)
> table(mtcars$carb,mtcars$gear)

Tugas Lab-4 :

> data1<-c(10,11,12,13,12,12,14,20,19,18,17,23,26,12,19,20,14,12,11,20);
> table(data1)
> hist(data1)

> utskel1 <-c(70,70,71,60,63,80,81,81,74,74,66,66)


> utskel2 <-c(67,67,67,68,67,67,77,77,77,80,80,80)
> utskel3 <-c(80,73,73,74,74,74,71,72,72,72,72,83)
> utkkel4 <-c(84,84,84,84,75,75,75,75,75,75,75,75)
> utskel5 <-c(75,78,78,78,78,78,79,79,85,85,87,90)
> utskel6 <-c(93,94,94,87,87,89,75,81,82,82,89,60)
> nilaiUTS <-c(utskel1,utskel2,utskel3,utskel4,utskel5,utskel6)
> summary(nilaiUTS)
> hist(nilaiUTS)

v2.0 84
Tugas Lab-5 :

> data()
> ToothGrowth
> ?ToothGrowth
> str(ToothGrowth)
> hist(ToothGrowth$supp)
> hist(ToothGrowth$len)

Tugas Lab-6 :

> data()
> ?trees
> colnames(trees)
> dim(trees)
> str(trees)
> analisa <- trees
> hist(analisa$Height)

Tugas Lab-7 :

> data()
> ?state.x77 (state)
> state.x77
> colnames(state.x77)
# Perhatikan x dan y
> plot(state.x77[,3],state.x77[,6])
> plot(state.x77[,3],state.x77[,6], \
xlab="Illiteracy", \ ylab="High Scholl
Graduate", \
col=2,pch=16, main="Scatter Plot", \ sub="Illiteracy
vs High School Graduate"
)
> # lm(y ~ x)
> lm(state.x77[,6] ~ state.x77[,3])
> abline(lm(state.x77[,6] ~ state.x77[,3]), \
lwd=2,col="blue")
Pertanyaan :
1. Kenapa menggunakan notasi state.x77[,3] dan tidak mengguanakan notasi sta-
te.x77$Illiteracy ?
2. Kenapa menggunakan notasi lm(state.x77[,6] ~ state.x77[,3]) dan tidak menggua- nakan
notasi lm(state.x77HSGrad state.x77Illiteracy) ?

Tugas Lab-8 :

> state.x77
> colnames(state.x77)
> hist(state.x77$Income, xlab="Income", \
main="Histogram of Income")
> hist(state.x77[,2])

Pertanyaan : Apa yang terjadi ?

Tugas Lab-9 :

> state.x77
> colnames(state.x77)
> state.x77df <- as.data.frame(state.x77)
> hist(state.x77df$Income, xlab="Income", \
main="Histogram of Income")
> par(mfrow=c(1,2))
> hist(state.x77[,2])
> hist(state.x77[,2],prob=TRUE)
> lines(density(state.x77[,2]))

Tugas Lab-10 :

> state.x77
> par(mfrow=c(1,2))
> hist(state.x77[,2],xlab="Income", \
main="Histogram of Income")
> hist(state.x77[,2],prob=TRUE, \
xlab="Income", \
main="Histogram of Income",col="grey")
> lines(density(state.x77[,2]),lwd=2)

Tugas Lab-11 :

#vertikal
> boxplot(state.x77[,5])
#horizontal
> boxplot(state.x77[,5],horizontal=TRUE)

Tugas Lab-12 :

> par(mfrow=c(1,2))
> boxplot(state.x77[,c(1:3)],xlab="variable")
> boxplot(state.x77[,5],xlab="Murder Rate")

Tugas Lab-13 :

> kelasA <-c(12.9,13.5,12.8,13.6,17.2 13.2, \


12.6,15.3,14.4,11.3)
> kelasB <-c(14.7,15.6,15.0,15.2,16.8,20.0, \
12.0,15.9,16.0,13.1)
> length(A);length(B)
> gab <- cbind(A,B)
> boxplot(gab, xlab="Kelas", ylab="waktu dlm detik")

Mana yang lebih cepat kelas A atau kelas B ?


Tugas Lab-14 :

>state.x77
>str(state.x77)
>state.x77df <- as.data.frame(state.x77)
>colnames(state.x77df)
>rownames(state.x77df)
>state.x77df[1]

Tugas Lab-15 :
Misalnya Income dikelompokkan dalam tiga kelompok, yakni “low”, “medium” dan kelompok
“high”. Dimana “low” adalah income kurang dari 4000, medium, “income” antara 4000 s.d
4800 dan “high”, income lebih dari 4800.
Variabel pengelompokkan baru ini kemudian kita sebut sebagai variabel Income-
Code

# Box plot untuk beberapa group


# Recode dari Income dan dimasukkan ke dalam dataset # sebagi
variabel baru
> state.x77df$IncomeCode <- cut(state.x77df$Income, \
breaks=c(-Inf,4000,4800,Inf),\
labels=c("low","medium","high") )
# Jika variabel berjenis factor, maka otomatis membentuk boxplot
> plot(state.x77df$IncomeCode,state.x77df$Illiteracy)

Tugas Lab-16 :

> bandingTampilan <-c(0, 7, 9, 15, 19, 13, \


8, 4, 24, 8)
> hist(bandingTampilan)
> barplot(bandingTampilan)
Tugas Lab-17 :

> grupIncome <-table(state.x77df$IncomeCode)


> grupIncome
#diagram batang
> barplot(grupIncome,xlab="Income Group", \
ylab="Frekuenci")
> barplot(grupIncome,xlab="Income Group",\
ylab="Frekuensi",col=rainbow(6))
> barplot(grupIncome,xlab="Income Group", \
ylab="Frekuensi",density=c(10,20,50), \
border="blue", col=2)

You might also like