Overview

Description

Plot the empirical distribution of categorical longitudinal data.

Usage

catplotmlx(r, breaks = NULL)

Arguments

r
a data frame with a column id, a column time, a column with values and possibly a column group.
breaks
one of:

Value

a ggplot object.


Examples

Basic examples

catModel <- inlineModel("
[LONGITUDINAL]
input =  {a,b}
EQUATION:
lp1=a-b*t
lp2=a-b*t/2

p1 = 1/(1+exp(-lp1))
p2 = 1/(1+exp(-lp2)) - p1
DEFINITION:
y = {type=categorical, categories={A, B, C}, 
     P(y=A)=p1, P(y=B)=p2}
")

out  <- list(name='y', time=seq(0, 100, by=4))

Ng  <- 1000
g1 <- list(size=Ng, parameter=c(a=6,b=0.2))
res <- simulx(model=catModel, output=out, group=g1)
plot1 <- catplotmlx(res$y)
print(plot1)

You can modify the location of the breaks and/or the color

plot2 <- catplotmlx(res$y, breaks=seq(-2,102,by=8), color="purple") 
print(plot2)

or define the number of breaks instead of the location,

plot3 <- catplotmlx(res$y,breaks=5, color="#490917") 
print(plot3)

catplotmlx returns a list of tables with plot=FALSE

cat.out <- catplotmlx(res$y, color="#490917", breaks=5, plot=FALSE)
print(cat.out)
## $color
## [1] "#4909174D" "#49091799" "#490917E6"
## 
## $y
##   time baseline      A         B C
## 1  8.4        0 0.9798 0.9950000 1
## 2 29.2        0 0.5826 0.9580000 1
## 3 50.0        0 0.0365 0.7186667 1
## 4 70.8        0 0.0006 0.2410000 1
## 5 91.6        0 0.0000 0.0476000 1


Using catplotmlx with groups

If a column group exists in the data, then catplotmlx will creat a graph per group.

g2 <- list(size=Ng, parameter=c(a=10,b=0.2))
res <- simulx(model=catModel, output=out, group=list(g1,g2))
plot4 <- catplotmlx(res$y) 
print(plot4)

The labels of the subplots can be defined by the user.

g3 <- list(size=Ng, parameter=c(a=6,b=0.4))
g4 <- list(size=Ng, parameter=c(a=10,b=0.4))
res <- simulx(model=catModel, output=out, group=list(g1,g2,g3,g4))
group.labels <- c("a=6,  b=0.2", "a=10,  b=0.2", "a=6,  b=0.4", "a=10,  b=0.4")
plot5 <- catplotmlx(res$y, labels=group.labels) 
print(plot5)

A unique graph is produced by ignoring the group

plot6 <- catplotmlx(res$y, group="none") 
print(plot6)

If group is defined by two factors, catplotmlx will automatically layout panels in a grid (using facet_grid)

cov <- data.frame(id=levels(res$y$id), a=rep(c(6,10,6,10), each=Ng), b=rep(c(0.2,0.2,0.4,0.4), each=Ng) )
plot7 <- catplotmlx(res$y, group=cov) 
print(plot7)