Loading data set

bmi.and.chol <- read.csv("/cloud/project/bmi and chol.txt", sep="")
#cor.test()?
#View(bmi.and.chol)
#bmi.and.chol
#View(bmi.and.chol) # function View() show as table 
age <- bmi.and.chol$age # set age as avai from bmi.and.chol
chol <- bmi.and.chol$chol # set chol as avai from bmi.and.chol
cor.test(age,chol) # read cor.test () function
## 
##  Pearson's product-moment correlation
## 
## data:  age and chol
## t = 10.704, df = 16, p-value = 1.058e-08
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.8350463 0.9765306
## sample estimates:
##       cor 
## 0.9367261
cor.test(age,chol, method = "spearman") 
## Warning in cor.test.default(age, chol, method = "spearman"): Cannot compute
## exact p-value with ties
## 
##  Spearman's rank correlation rho
## 
## data:  age and chol
## S = 51.158, p-value = 2.57e-09
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##      rho 
## 0.947205
plot(age,chol)# plot(x,y) x,y numberical

cor.test(age,chol, method = "kendall") 
## Warning in cor.test.default(age, chol, method = "kendall"): Cannot compute exact
## p-value with ties
## 
##  Kendall's rank correlation tau
## 
## data:  age and chol
## z = 4.755, p-value = 1.984e-06
## alternative hypothesis: true tau is not equal to 0
## sample estimates:
##       tau 
## 0.8333333
lm(chol~age) # lm(y~x) as linear mode 
## 
## Call:
## lm(formula = chol ~ age)
## 
## Coefficients:
## (Intercept)          age  
##     1.08922      0.05779
reg <- lm(chol~age) #set reg as ... 
summary(reg) # show inf of reg
## 
## Call:
## lm(formula = chol ~ age)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.40729 -0.24133 -0.04522  0.17939  0.63040 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 1.089218   0.221466   4.918 0.000154 ***
## age         0.057788   0.005399  10.704 1.06e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3027 on 16 degrees of freedom
## Multiple R-squared:  0.8775, Adjusted R-squared:  0.8698 
## F-statistic: 114.6 on 1 and 16 DF,  p-value: 1.058e-08
fitted(reg) # calculate Y^ (predict Y)
##        1        2        3        4        5        6        7        8 
## 3.747483 2.244985 4.094214 2.822869 4.383156 2.533927 2.707292 3.169600 
##        9       10       11       12       13       14       15       16 
## 2.360562 3.574118 4.383156 2.996234 2.360562 4.729886 3.400753 3.863060 
##       17       18 
## 2.707292 3.920849
resid(reg) # calculate residual (phan du) of reg 
##            1            2            3            4            5            6 
## -0.247483426 -0.344985415 -0.094213736 -0.222869265  0.116844338  0.466072660 
##            7            8            9           10           11           12 
##  0.192707505  0.630400424 -0.260562185  0.225881729 -0.283155662  0.003765579 
##           13           14           15           16           17           18 
##  0.139437815 -0.129885972 -0.200753116  0.336939804 -0.407292495  0.079151419
#op <- par(mfrow= c(2,2)) # chia man hinh ra 4 phan #op <-par(mar=c(1,1,1,1)) 
op <-par(mar=c(1,1,1,1)) # lenh chia man hinh
plot(reg) # ve cac do thi (co the co) trong reg

#abline(chol~age)
#op <-par(mar=c(1,0,0,0)) # chua biet tra ve sao cho nguyen o
#graphics.off()
plot(chol ~ age, pch=16) 
abline(reg,col="red")