lagVar {epicalc}R Documentation

Create a vector of lagged or subsequent value

Description

Create a vector of lagged or subsequent value in a long form longitudinal data

Usage

lagVar(var, id, visit, lag.unit=1)

Arguments

var variable to create the lag
id subject identification field
visit visit of measurement
lag.unit lag number of visits

Details

Data must be in long format having variable to create the lag, id and visit.

The variable 'visit' must be the number of visit, with step = 1.

The default value of lag.unit is 1. When the number is negative, the next measured is created instead.

Author(s)

Virasakdi Chongsuvivatwong <cvirasak@medicine.psu.ac.th>

See Also

'lag'

Examples

## Identification of the tree that became smaller during followup
data(Sitka, package="MASS")
use(Sitka)
table(Time)
visit <- Time
pack()
recode(visit, as.numeric(names(table(Time))), 1:5)
lag1.size <- lagVar(var=size, id=tree, visit=visit, lag=1)
data.frame(tree=tree, time=Time, visit=visit, size=size, lag1.size=lag1.size) [1:20,]
# Answer
data.frame(Time, tree, size, lag1.size) [which(lag1.size > size),]

# Alternatively
next.size <- lagVar(size, tree, visit, lag=-1)
data.frame(tree=tree, time=Time, size=size, next.size=next.size) [1:20,]
data.frame(Time, tree, size, next.size) [which(size > next.size),]


[Package epicalc version 2.10.1.1 Index]