data <- read.table('e://kg.txt',
header = TRUE,
sep = '\t')
data <- data %>% as_tibble()
data %>% attach()
data %>% ggplot(aes(cm, kg))+ geom_line()
data %>% ggplot(aes(age,cm))+ geom_line()
data %>% ggplot(aes(age,kg))+ geom_line()
data[1:3] %>% cor() %>% corrplot::corrplot(method = "color",
addCoef.col = "grey")
lm_data <- data %>% lm(kg~I(cm^3),.)
lm_data %>% summary()
lm_data
plot(cm^3,kg,xaxt='n');
axis(1,at=cm^3,labels=cm);
abline(lm_data)
data %>% ggplot(aes(cm^3,kg)) +
geom_point() +
geom_smooth()
library(tidyverse)
ht_weight_df <- read.table("e://01_heights_weights_genders.txt",
header = TRUE,
sep = "\t") %>%
as_tibble()
ht_weight_df %>% mice::md.pattern()
ht_weight_df %>% select(-1) %>%
cor() %>% corrplot::corrplot(method = "color",
addCoef.col = "grey")
ht_weight_df %>% select(-1) %>% sample_frac(0.1) %>%
plot(cex = 0.1)
lm_ht_weight <- lm(Weight ~ Height, data = ht_weight_df)
lm_ht_weight %>% summary()
lm_ht_weight %>% abline()
ht_weight_df %>% group_by(Gender) %>%
dplyr::summarise( round( mean( Height)* 2.54))
par(mfrow = c(1,1))
ht_weight_df %>% subset(Gender == "Male") %>% select(Height) %>%
unlist() %>% as.numeric() %>%
density() %>% plot(type = "h", col = 4, ann = FALSE)
ht_weight_df %>% subset(Gender == "Female") %>% select(Height) %>%
unlist() %>% as.numeric() %>%
density() %>% lines(col = 2)
title(main = "Height By Gender")
abline(col = c(1, 2),
lty = 3,
v = c(
mean(ht_weight_df %>% subset(Gender == "Male") %>%
select(Height) %>% unlist()),
mean(ht_weight_df %>% subset(Gender == "Female") %>%
select(Height) %>% unlist())
))
ht_weight_df %>% ggplot(aes(x = Height, colour = Gender)) +
geom_density()
ht_weight_df %>% ggplot(aes(sample = Height)) +
geom_point(stat = "qq") + facet_wrap(~Gender)
ht_weight_df %>% ggplot(aes(x = Height, y = Weight, colour = Gender)) +
geom_point(alpha = 0.2) +
geom_smooth(method = "lm", formula = y ~ x)
lm_ht_wt_by_gender <- lm(Weight ~ Height * Gender, data = ht_weight_df)
lm_ht_wt_by_gender %>% summary()
- 如果观察人的一生,身高、体重的变化曲线,会是什么样的呢?