Professional Documents
Culture Documents
Probabilitas &
Statsitika
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 :
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)
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])
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 :
>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
Tugas Lab-16 :