Đọc dữ liệu, mô tả đặc điểm và đò thị tán xạ

df=read.csv("D:\\Download\\Demo.csv")
library(table1)
## 
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
## 
##     units, units<-
table1(~ height + weight|gender, data=df)
F
(N=862)
M
(N=355)
Overall
(N=1217)
height
Mean (SD) 153 (5.55) 165 (6.73) 157 (7.98)
Median [Min, Max] 153 [136, 170] 165 [146, 185] 155 [136, 185]
weight
Mean (SD) 52.3 (7.72) 62.0 (9.59) 55.1 (9.40)
Median [Min, Max] 51.0 [34.0, 95.0] 62.0 [38.0, 95.0] 54.0 [34.0, 95.0]
plot(weight ~ height,data=df)

cor.test(df$height , df$weight, data=df) 
## 
##  Pearson's product-moment correlation
## 
## data:  df$height and df$weight
## t = 25.984, df = 1215, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5602911 0.6326135
## sample estimates:
##       cor 
## 0.5976667

Nhân xét: Cân nặng và chiều cao có mối tương quan với hệ số 0.5976667

Với khoảng tin cậy 95%, hệ số tương quan từ 0.560291 đến 0.6326135

Phân tích mối tương quan giữa chiều cao (height) và tỉ trọng mỡ (pcfat)

plot(height ~ pcfat,data=df)

cor.test(df$pcfat , df$height, data=df)
## 
##  Pearson's product-moment correlation
## 
## data:  df$pcfat and df$height
## t = -19.063, df = 1215, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.5219407 -0.4353664
## sample estimates:
##        cor 
## -0.4798206

Nhân xét: Cchiều cao và tỷ lệ mỡ có mối tương quan với hệ số-0.4798206(nghịch biến)

Với khoảng tin cậy 95%, hệ số tương quan từ-0.521940 đến -0.43536645

Phân tích định lượng Chiêu cao và Cân nặng

Hwm=lm (height ~ weight, data=df)
summary(Hwm)
## 
## Call:
## lm(formula = height ~ weight, data = df)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -22.2555  -4.1440  -0.1719   4.2514  20.8142 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 128.76781    1.09141  117.98   <2e-16 ***
## weight        0.50697    0.01951   25.98   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.399 on 1215 degrees of freedom
## Multiple R-squared:  0.3572, Adjusted R-squared:  0.3567 
## F-statistic: 675.2 on 1 and 1215 DF,  p-value: < 2.2e-16
plot(height ~ weight, data=df)
abline(Hwm, col = "red", lwd = 2)

### Quan hệ: Height= 128.76781+ 0.50697* weight ## Phân tích định lượng Chiêu cao và tỷ lệ mỡ

Hfm=lm (height ~ pcfat, data=df)
summary(Hfm)
## 
## Call:
## lm(formula = height ~ pcfat, data = df)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -22.5478  -4.4976  -0.2061   4.5024  28.3801 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 173.56668    0.90606  191.56   <2e-16 ***
## pcfat        -0.53292    0.02796  -19.06   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.002 on 1215 degrees of freedom
## Multiple R-squared:  0.2302, Adjusted R-squared:  0.2296 
## F-statistic: 363.4 on 1 and 1215 DF,  p-value: < 2.2e-16
plot(height ~ pcfat, data=df)
abline(Hfm, col = "red", lwd = 2)

### Quan hệ: Height= 173.56668 -0.53292* pcfat