Q1

library(nlme)
library(dplyr)
pacman::p_load(lattice, nlme)
nlme::Oxboys %>% 
  as.data.frame() %>% 
mutate(Subject = reorder(Subject, height, mean)) %>%
  xyplot(height ~ age | Subject, data = ., type = c("p", "r"))

Q2

library(ggplot2)
read.csv("income_tw.csv", header = T) %>% 
  mutate(Percent = (Count / sum(Count)) * 100,
         Income = ordered(Income, levels = Income)) %>%  
  ggplot(aes(x = Percent, y = Income)) +
  geom_point() +
  labs(x = "Percent(%)")

Q3

Q3.1 Are there gender differences in the three IQ scores?

library(tidyr)
read.table("brainsize.txt", header = T) %>%
  gather(IQtype, IQvalue, 3:5) %>% 
  ggplot(aes(IQtype, IQvalue, color = Gender)) +
  stat_summary(fun.data = mean_se, geom = "pointrange",
               size = rel(1.1), position = position_dodge(0.3))

FSIQ和VIQ有性別差異,PIQ可能沒有。


Q3.2 Is the relationship between height and weight gender dependent?

read.table("brainsize.txt", header = T)%>%
ggplot(aes(Height, Weight)) +
  geom_point(aes(color = Gender)) +
  stat_smooth(aes(color = Gender), method = "lm", se = F)

身高和體重的關聯有性別差異。


Q3.3Is the relationship between IQ and brainsize (as measured by MRIcount) gender dependent?

read.table("brainsize.txt", header = T) %>%
  gather(IQtype, IQvalue, 3:5) %>% 
  ggplot(aes(IQvalue, MRICount, color = Gender)) +
  geom_point() +
  stat_smooth(method = "lm", se = F) +
  facet_grid(. ~ IQtype) +
  labs(y = "Brain Size")

三種IQ得分和腦尺寸的關聯有性別差異。