createNewOnset: Returns data.table of lag-1 onset variables with 3 different...

Description Usage Arguments Details Value Examples

Description

This stand-alone scoring function takes a wide-form data.table or dataframe of 'lifetime use' variables for a (presumably consecutive) set of waves, and transforms them into variables with the value 0 prior to first known alcohol use, 1 if the individual is about to onset in the next wave, and 2 if he/she had already onset at some earlier wave. The onset event is lagged one wave (as for 'createNbhdOnset'). The variables returned by this function provide a particularly nice descriptive context for onset events–if you graph them in a network plot and assign, say, different node colors to each value, you can see who had or had not started (drinking, say) as of wave w, along with affiliations of everyone who was about to start in the next wave.

Usage

1
createNewOnset(pInDT, pTHold = 1)

Arguments

pInDT

A data.table (or dataframe) containing SID plus a lifetime use (NA, 0, >0) variable for each of c-1 ordered time periods, where c is the number of columns in the DF.

pTHold

The threshold (numerical value) for lifetime use; if the input use variable value is >= pTHold, then the event 'occurred'.

Details

The value of the output for an individual is coded 2 from the wave he/she onsets to the final wave. IF (and only if) an affirmative 'no onset' (value < pTHold) response is found, the previous wave is then given the value 1 ("ABOUT to onset"). An NA that follows only other NAs or 'no onset' values is always coded NA. An NA that follows an event (value >= pTHold) is always coded 2. An NA that precedes a 'no onset' value is coded 0. An NA that precedes an event is an NA, unless it is followed by a 'no onset' before the event occurs, in which case it is a zero, or if JUST before the event, a 1.

Value

A data.table of the same dimension as the input data table, with rows transformed into up-only variables suitable for descriptive use.

Examples

1
2
3
4
5
6
7
8
9
# Returns a table of 1-period lagged up-only variables which have the value 0
# before the first known lifetime alcohol use (if any such times are
# available), 1 on the occasion prior to onset, and 2 thereafter.
# The pTHold value of 1 means *any* use.
netList <- getNetworkSet(pWavVec = c(1,3,4), pSchVec = c(3,4,5,6,30))
ccTbl <- getNQTVCs(pWavVec = c(1,3,4), pSchVec = c(3,4,5,6,30))
alcLifeLag <- makeTVTbl(ccTbl, netList[[4]], pVar = "AL",
    pCut = c(0, .5, 1, 5, 20), pMaxNA = 3)
alcNewOnset <- createNewOnset(alcLifeLag, pTHold = 1)

johninpdx/RSTools documentation built on May 19, 2019, 5:15 p.m.