# 通過誤差條以圖形方式比較權重與時間

``````# Set seed to create reproducible example data
set.seed(50)

# Create patient ID numbers, genders, and ages
control <- NULL
control\$Age_0 = round(runif(200,1,10), digits = 1)

# Create monthly weights
control\$Weight_0  = ((control\$Age_0 + 4) * 2)
control\$Weight_1  = (control\$Weight_0 * 1.1)
control\$Weight_2  = (control\$Weight_0 * 1.2)
control\$Weight_3  = (control\$Weight_0 * 1.3)
control\$Weight_6  = (control\$Weight_0 * 1.4)
control\$Weight_9  = (control\$Weight_0 * 1.6)
control\$Weight_12 = (control\$Weight_0 * 1.8)

# Store as data frame
control <- as.data.frame(control)
``````

``````# Plot mean weights versus time
plot(c(0,1,2,3,6,9,12), c(mean(control\$Weight_0), mean(control\$Weight_1), mean(control\$Weight_2), mean(control\$Weight_3), mean(control\$Weight_6), mean(control\$Weight_9), mean(control\$Weight_12)), xlab = "Month", ylab = "Weight (Kilograms)", main = "Weight versus time", ylim = c(0,50))
``````

1. 我應該標出標準偏差，標準誤差還是95％置信區間？
2. 如何在繪圖中添加垂直誤差線？

``````# Create patient ID numbers, genders, and ages
growth <- NULL
growth\$Age_0 = round(runif(200,1,10), digits = 1)

# Create monthly weights
growth\$Weight_0  = ((growth\$Age_0 + 6) * 2)
growth\$Weight_1  = (growth\$Weight_0 * 1.3)
growth\$Weight_2  = (growth\$Weight_0 * 1.4)
growth\$Weight_3  = (growth\$Weight_0 * 1.6)
growth\$Weight_6  = (growth\$Weight_0 * 1.8)
growth\$Weight_9  = (growth\$Weight_0 * 1.9)
growth\$Weight_12 = (growth\$Weight_0 * 2.0)

# Store as data frame
growth <- as.data.frame(growth)

plot(c(0,1,2,3,6,9,12), c(mean(growth\$Weight_0), mean(growth\$Weight_1), mean(growth\$Weight_2), mean(growth\$Weight_3), mean(growth\$Weight_6), mean(growth\$Weight_9), mean(growth\$Weight_12)), xlab = "Month", ylab = "Weight (Kilograms)", main = "Weight versus time", ylim = c(0,50))
``````
1. 這會改變我應該創建的誤差線的類型嗎（即，如果我要檢查組之間是否存在差異，是否應該使用置信區間）？
2. 如何在與對照組相同的地塊上繪製該圖？

If you reshape the data to long form it might be easier to play with using `ggplot2` graphics. The `reshape` package can help with this. Long form is where each row of the data frame has one measurement value and all the corresponding time, age, and gender variables. There's a lot of repetition (each subject has multiple rows) but its way ggplot likes to eat your data (and other packages benefit from it too...).

Then you can do boxplots of weight for each age, which show more than just a mean and standard error. Violin plots can give you even more. Possibly too much if you don't have much data.

As for testing if the growth hormone works, Rutherford once said “If your experiment needs statistics, you ought to have done a better experiment.” But seriously, this looks like a standard linear mixed effects model. See `nlme` package.