Data display in R for repeated measurements

Data display in R for repeated measurements

Graphical display of the data can be perform using the graphics package (e.g. plot function, boxplot function). However for constructing complex graphics that typically arise when dealing with repeated measurement other packages may be more convenients. Two packages will be used during this course:

? the lattice package: it is invoqued when using the plot functions from the nlme or lmer package.

? the ggplot2 package: it implements a specific grammar for bulding graphics. Once familiar with this grammar, you can produce nice and flexible displays of your data. However, this grammar may be not straightforward to understand/use at first sight and won't be explayed here. If you are interested, you can easily find tutorials on internet or look at the book (Wickham 2009).

Data set:

str(dtL.data)

## Classes data.table and data.frame : 80 obs. of 6 variables:

## $ Id

: Factor w/ 50 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...

## $ Gender : Factor w/ 2 levels "Female","Male": 2 2 1 1 1 1 2 2 2 2 ...

## $ Treatment: Factor w/ 2 levels "No","Yes": 2 2 2 1 1 2 1 1 1 2 ...

## $ Age

: num 1.216 0.331 1.39 0.872 -1.081 ...

## $ time

: Factor w/ 4 levels "time1","time2",..: 1 1 1 1 1 1 1 1 1 1 ...

## $ outcome : num 1.22 1.23 5.29 8.87 3.95 ...

## - attr(*, ".internal.selfref")=

1

lattice

Data display

library(lattice) xyplot(outcome ~ time, data = dtL.data)

outcome

15 10

5 0

time1

time2

time

time3

time4

2

xyplot(outcome ~ time, group = Id, data = dtL.data, type = "b")

outcome

15 10

5 0

time1

time2

time

time3

time4

3

xyplot(outcome ~ time | Treatment, data = dtL.data)

No

15

time1

time2 time3

Yes

time4

10

outcome

5

0

time1

time2

time3

time4

time

4

xyplot(outcome ~ time | Treatment, group = Id, data = dtL.data, type = "b")

No

15

time1

time2 time3

Yes

time4

10

outcome

5

0

time1

time2

time3

time4

time

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download