2
$\begingroup$

I have a group of 200 children who came to clinic at months 0, 1, 2, 3, 6, 9, and 12 this year. At each clinic visit the children were weighed.

# 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)

I want to study how their weights vary with time. I thought the best way to do this would be to simply plot their mean weights at every visit versus time.

# 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))

I would like to put some vertical error bars on this plot. My questions are:

  1. Should I plot standard deviation, standard error, or a 95% confidence interval?
  2. How do I add vertical error bars to the plot?

There is another group of children who got growth hormone injections during the year. I want to compare their growth over time to that of the children in the control group.

# 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. Does this change the kind of error bars I should create (i.e., should I use confidence intervals if I want to examine whether or not there is a difference between the groups)?
  2. How do I plot this on the same plot as the control group?

Am I thinking of this problem the right way? Any other suggestions?

$\endgroup$

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ (+1) Thanks a ton for your help. I managed to make a violin plot and also think that I have reshaped the data correctly. Am still having a bit of trouble with stratification and other analyses though. I posted a new question: stats.stackexchange.com/questions/66030/… $\endgroup$
    – Alexander
    Commented Jul 30, 2013 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.