The body fat was measured, using dual-energy x-ray absorptiometry, in several hundred children at age 11, 13, and 15 years.
Use the data set (in Stata dta format) to answer the following questions:
(a) Does body fat increase with age for both girls and boys?
(b) Is there a difference between girls and boys with respect to the increase of the body fat with age?
(c) Do girls tend to have more body fat than boys?
Source: Vach, W. (2013). Regression Models as a Tool in Medical Research. p. 330. Chapman/Hall & CRC Press.
Column 1: Subject ID
Column 2: Gender ID
Column 3: Age in years
Column 4: Body fat in kilograms
pacman::p_load(foreign)
dta3 <- read.dta("C:/Users/HANK/Desktop/HOMEWORK/bodyfat.dta",
convert.dates = TRUE,
convert.factors = TRUE,
missing.type = FALSE,
convert.underscore = FALSE,
warn.missing.labels = TRUE)
str(dta3)## 'data.frame': 2273 obs. of 4 variables:
## $ id : num 1 1 1 2 2 2 3 3 3 4 ...
## $ sex : Factor w/ 2 levels "female","male": 2 2 2 1 1 1 1 1 1 1 ...
## $ age : num 11 13 15 11 13 15 11 13 15 11 ...
## $ bodyfat: num 4 6.2 10.5 8.1 10.4 ...
## - attr(*, "datalabel")= chr ""
## - attr(*, "time.stamp")= chr "21 May 2011 13:30"
## - attr(*, "formats")= chr [1:4] "%9.0g" "%9.0g" "%9.0g" "%9.0g"
## - attr(*, "types")= int [1:4] 254 254 254 254
## - attr(*, "val.labels")= chr [1:4] "" "labsex" "" ""
## - attr(*, "var.labels")= chr [1:4] "group(u)" "" "" ""
## - attr(*, "version")= int 8
## - attr(*, "label.table")=List of 1
## ..$ labsex: Named int [1:2] 1 2
## .. ..- attr(*, "names")= chr [1:2] "female" "male"
## id sex age bodyfat
## 1 1 male 11 4.0
## 2 1 male 13 6.2
## 3 1 male 15 10.5
## 4 2 female 11 8.1
## 5 2 female 13 10.4
## 6 2 female 15 15.2
ggplot(dta3, aes(age, bodyfat,
group = id,
color = id)) +
geom_point()+
stat_summary(fun = mean, geom = "line") +
#stat_summary(fun = mean, geom = "point") +
#stat_summary(fun.data = mean_se, geom = "errorbar", width = 0.3) +
#scale_shape_manual(values = c(1, 2)) +
facet_wrap( ~ sex)+
labs(x = "Age (in years)",
y = "Body fat (in %)") +
theme(legend.justification = c(1, 1),
legend.position = c(1, 1),
legend.background = element_rect(fill = "white",color = "black"))