Turtorial7

莊耘、邱嘉品

20180611

本組報告的文獻

Large-scale physical activity data reveal worldwide activity inequality
大規模的身體活動數據顯示全球身體活動量的差異

文獻裡的資料型態(只有平均數,無法以FDA進行統計)

文獻裡提供的檔案數

(為平均數的檔案,無法以FDA與一般方法進行比較)

文獻裡的統計圖表(使用ggplot)

載入package

library(fda)
Loading required package: splines
Loading required package: Matrix

Attaching package: 'fda'
The following object is masked from 'package:graphics':

    matplot
library(ggplot2)
Warning: package 'ggplot2' was built under R version 3.4.4
library(ggthemes)
Warning: package 'ggthemes' was built under R version 3.4.4
library(scales)
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

以package 裡的Dataset進行一般方法及FDA的比較

gr<-growth
hgtm1 <- gr[["hgtm"]] #男身高成長
hgtf1 <- gr[["hgtf"]] #女身高成長
age1 <- gr[["age"]] #年齡
head(hgtm1[,1:5]) #前五個男孩的前六筆資料
     boy01 boy02 boy03 boy04 boy05
1     81.3  76.2  76.8  74.1  74.2
1.25  84.2  80.4  79.8  78.4  76.3
1.5   86.4  83.2  82.6  82.6  78.3
1.75  88.9  85.4  84.7  85.4  80.3
2     91.4  87.6  86.7  88.1  82.2
3    101.1  97.0  94.2  98.6  89.4

算平均,定義 errorbar 的上下限

hgtm1 <- as.data.frame(hgtm1) %>% 
  mutate(h_mean=apply(hgtm1,1,mean),h_sd = apply(hgtm1,1,sd))%>%
  mutate(lower.ci=h_mean-h_sd,upper.ci=h_mean+h_sd,gender="male")
hgtf1 <- as.data.frame(hgtf1) %>% 
  mutate(h_mean=apply(hgtf1,1,mean),h_sd = apply(hgtf1,1,sd))%>%
  mutate(lower.ci=h_mean-h_sd,upper.ci=h_mean+h_sd,gender="female")
hgtm1 <- cbind(hgtm1,age1)
hgtf1 <- cbind(hgtf1,age1)
dta1 <- rbind(hgtm1[,40:45],hgtf1[,55:60])
head(dta1)
    h_mean     h_sd lower.ci  upper.ci gender age1
1 76.09487 2.765858 73.32901  78.86073   male 1.00
2 79.86923 2.913594 76.95564  82.78282   male 1.25
3 83.22051 2.907991 80.31252  86.12850   male 1.50
4 86.21795 2.982305 83.23564  89.20025   male 1.75
5 88.75385 3.096080 85.65777  91.84993   male 2.00
6 97.33077 3.433439 93.89733 100.76421   male 3.00

作圖

dodgewidth = .35
p <- ggplot(dta1, aes(age1, h_mean, colour = gender)) #畫布
p <- p + stat_summary (fun.y = mean, geom = "point", 
         position = position_dodge(width = dodgewidth))#畫點
p <- p + stat_summary (fun.y = mean, geom = "line", 
       aes(group=gender), 
        position = position_dodge(width = dodgewidth)) #連線
p <- p + geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), 
       width = 0.0, 
       position = position_dodge(width = dodgewidth)) #加error bar
p <- p + scale_color_manual(
    values=c( "firebrick3","dodgerblue"))#改線顏色
p <- p + ylab("height(cm)") + xlab("age") #設 xy 軸名稱
p <- p + labs(colour = "") #拿掉圖例名稱
p <- p + theme_few(base_size=12, base_family="Helvetica") #拿掉背景

.

.

.

.

.

.

.

.

.

FDA package介紹

FDA 網站介紹

FDA package 裡的function

FDA 參考書籍

FDA 參考書籍

以FDA作圖,女生身高成長圖

girlGrowthSm <- with(growth, smooth.basisPar(argvals=age, y=hgtf, lambda=0.1))
plot(girlGrowthSm$fd, xlab="age", ylab="height (cm)",main="Girls in Berkeley Growth Study" )

[1] "done"

女生身高成長率

plot(deriv(girlGrowthSm$fd), xlab="age", ylab="growth rate (cm / year)",
main="Girls in Berkeley Growth Study" )

[1] "done"

女生身高成長加速度

plot(deriv(girlGrowthSm$fd, 2), xlab="age",
ylab="growth acceleration (cm / year^2)",
main="Girls in Berkeley Growth Study" )

[1] "done"

FDA 其他文獻的作圖參考

A Functional Data Analysis Approach for Circadian Patterns of Activity of Teenage Girls

FDA 其他文獻的作圖參考

FDA 其他文獻的作圖參考

本組的報告到此結束,謝謝老師及同學的聆聽。