mydata<-faithful #bo du lieu faithful
duration<-mydata$eruptions
mean(duration)
## [1] 3.487783
#ktra thuoc tinh
str(mydata)
## 'data.frame': 272 obs. of 2 variables:
## $ eruptions: num 3.6 1.8 3.33 2.28 4.53 ...
## $ waiting : num 79 54 74 62 85 55 88 85 51 85 ...
#ktra tong quan thong ke
summary(mydata)
## eruptions waiting
## Min. :1.600 Min. :43.0
## 1st Qu.:2.163 1st Qu.:58.0
## Median :4.000 Median :76.0
## Mean :3.488 Mean :70.9
## 3rd Qu.:4.454 3rd Qu.:82.0
## Max. :5.100 Max. :96.0
#trung vi
median(duration)
## [1] 4
#tu phan vi(quartile), bach phan vi
quantile(duration) #chia dl ->4p, 3 moc chia(dl tap trung tai q3-q1)
## 0% 25% 50% 75% 100%
## 1.60000 2.16275 4.00000 4.45425 5.10000
quantile(duration, c(0.30, 0.51, 0.77)) #bach phan vi
## 30% 51% 77%
## 2.3051 4.0000 4.5000
#khoang du lieu
max(duration)-min(duration) #do dai khoang bien thien
## [1] 3.5
range(duration) #khoang dau cuoi
## [1] 1.6 5.1
#dai phan vi/do bien thien cua phan vi(q3-q1)
IQR(duration) #dl nhieu: <q1-1,5*IQR or >q3+1,5*IQR
## [1] 2.2915
#ve bieu do hop(box and wisker plot)
boxplot(duration, horizontal = TRUE, notch = TRUE, col = "indianred1")

#phuong sai(dung cho 1 bien)
var(duration) #hiep phuong sai(cua 2 bien ngau nhien, co them +-, dong bien)
## [1] 1.302728
#he so tuong quan
waiting=faithful$waiting
cor(duration, waiting)
## [1] 0.9008112
#moment trung tam(kha nang ttrung cua dl trong 1 ko gian)
library(e1071)
duration<-faithful$eruptions
moment(duration, order=3, center=TRUE)
## [1] -0.6149059
skewness(duration) #<0 => lech trai
## [1] -0.4135498