You are on page 1of 2

library(lattice) # gambar

library(ellipse) # gambar
library(leaps) # regresi
library(locfit) # regresi local
library(nutshell) # sample data
library(lars) # teknik memperkecil error untuk regresi
library(car) # sample data

# data dummy
# x <- array(1:900, dim=c(100,3))

# menampilkan sebagian data


# head(x)
# data(births2006.smpl)
# data_kelahiran <- births2006

# mencari nilai kelahiran


# data_kelahiran$DMETH_REC

# menghilangkan unknown
# table(data_kelahiran$DMETH_REC)[-2]
# table(data_kelahiran$DMETH_REC)[-c(2,4)]

# dbwt = data_kelahiran$DBWT

# apply buat memberikan fungsi terhadap suatu data


# lapply for list
# sapply for string
# min apply(data_kelahiran, 2, min)
# max apply(data_kelahiran, 2, max)

# mean apply(data_kelahiran, 2, mean)

# lihat summary data


# summary(data_kelahiran)

# define list
# data_list <- list(a = 1:10, beta = exp(-3:3), logic = c(TRUE,FALSE,FALSE,TRUE))
# lapply(data_list,max)

#subs fungsi table untuk mengkelompokan nilai

#subset for filter data


head(subset(data_kelahiran, DMEDUC == '2 years of college'))
head(subset(data_kelahiran, TBO_REC > 1))

DAN
#Contoh--Correlation
Problem
Find the correlation coefficient of the eruption duration and waiting time in the data set faithful.
Observe if there is any linear relationship between the variables.
Solution
We apply the cor function to compute the correlation coefficient of eruptions and waiting.
> duration = faithful$eruptions # the eruption durations
> waiting = faithful$waiting
> cor(duration, waiting)

# the waiting period


# apply the cor function

[1] 0.90081
Answer
The correlation coefficient of the eruption duration and waiting time is 0.90081. Since it is close to
1, we can conclude that the variables are positively linearly related.

You might also like