library(readr)
mice_weights <- read_csv("mice_weights.csv")
## Rows: 780 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): sex, diet
## dbl (6): rownames, body_weight, bone_density, percent_fat, gen, litter
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
data1 <- mice_weights
Dữ liệu được cung cấp bởi Karen Svenson từ Phòng thí nghiệm Jackson. Nguồn tài trợ để tạo ra những dữ liệu này đến từ khoản trợ cấp P50 GM070683 của NIH được trao cho Gary Churchill.
dateset gồm 7 biến:
body_weight: Trọng lượng cơ thể tính bằng gam ở tuần thứ 19.
bone_density: Mật độ cơ thể.
percent_fat: Phần trăm chất béo.
sex: Giới tính của chuột.
diet: Chế độ ăn của chuột: chow hoặc nhiều chất béo.
gen. Đây là những con chuột outbread. Biến này biểu thị thế hệ.
liiter: Con nào trong hai lứa chuột thuộc về.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library("scales")
## Warning: package 'scales' was built under R version 4.3.3
##
## Attaching package: 'scales'
## The following object is masked from 'package:readr':
##
## col_factor
library("ggplot2")
## Warning: package 'ggplot2' was built under R version 4.3.3
summary(data1$body_weight)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 18.13 28.09 32.98 34.08 39.37 65.15
d <- data_frame(data1)
## Warning: `data_frame()` was deprecated in tibble 1.1.0.
## ℹ Please use `tibble()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
df <- d %>%
mutate(body_weight = case_when(
body_weight <= 30 ~ "Underweight",
body_weight <= 40 ~ "Normal weight",
body_weight <= 66 ~ "Overweight",
TRUE ~ "Obese"
))
print(df)
## # A tibble: 780 × 8
## rownames body_weight bone_density percent_fat sex diet gen litter
## <dbl> <chr> <dbl> <dbl> <chr> <chr> <dbl> <dbl>
## 1 1 Underweight 0.616 7.26 F chow 4 1
## 2 2 Underweight 0.769 4.95 F chow 4 1
## 3 3 Underweight 0.684 6.02 F chow 4 1
## 4 4 Normal weight 0.644 9.54 F chow 4 1
## 5 5 Underweight 0.530 6.99 F chow 4 1
## 6 6 Underweight 0.565 6.77 F chow 4 1
## 7 7 Underweight 0.662 7.98 F chow 4 1
## 8 8 Underweight 0.514 7.93 F chow 4 1
## 9 9 Underweight 0.536 6.92 F chow 4 1
## 10 10 Normal weight 0.714 7.31 F chow 4 1
## # ℹ 770 more rows
tt <- table(df$body_weight)
# Biểu đồ đường cho bảng tần suất
plot(tt, type = "o", main = "Frequency Distribution of Body Weight", xlab = "Body Weight", ylab = "Frequency")
tu <- table(df$diet)
# Biểu đồ cột cho bảng tần suất
barplot(tu,
main = "Frequency Distribution of Diet",
xlab = "Diet",
ylab = "Frequency",
col = "skyblue")
ti <- table(df$sex)
# Biểu đồ cột cho biến sex
barplot(ti,
main = "Frequency Distribution of Sex",
xlab = "Sex",
ylab = "Frequency",
col = c("blue", "pink"),
legend.text = TRUE)
# **Ước lượng tỷ lệ**