Learn R Programming

DySeq (version 0.13)

StateExpand: StateExpand

Description

Transforms dyadic binary data into state-expand-sequences (combines two corresponding sequences into one for every row of a dataframe)

Usage

StateExpand(x, pos1, pos2, replace.na = FALSE)

Arguments

x
Dataframe or matix containing the sequences that should be combined
pos1
a vector that indicates all columns of the first sequence
pos2
a vector that indicates all columns of the second sequence
replace.na
a numeric that is used for replacement. If FALSE: no replacement will take place! 0 is handled as zero in this case not als FALSE!

Value

returns a matrix with the combined sequences.

Details

Takes a dataframe or matrix with dyadic binary data in wide data format, that is:
  • one observation unit (for example one couple) is represented by one row
  • every observation unit has two sequences with the same length
  • entrys must be corresponding to each other (for example they represent same time intervalls)
  • every sequence contains only zeros and/or ones (for example behavior is shown or not)

and transforms it into state-expand-sequences:

  • one sequence per observation unit that contains the same information as before
  • every entry represents the combination of the corresponding previous entrys
  • 0 represents two former zeros,
  • 1 represents a one in the first sequence and a zeros in the second
  • 2 represents a zero in the first sequence and a one in the second
  • 3 represents a one in both former sequeces

why/how to use:

  • Most packages are only suited for univariat sequence analysis.
  • This function transforms dyadic dequences into univariate sequences.
  • state-expand-sequences are needed for some of the other functions of this package.

References

  • Bakeman, R., & Gottman, J. M. (1997)
  • Kenny, D. A., Kashy, D. A., & Cook, W. L. (2006)

Examples

Run this code
 # Example 1
 data(CouplesCope) # Load sample data
 CouplesCope[1:5,] # inspect first five cases

 my.expand<-StateExpand(CouplesCope, 2:49, 50:97)
 my.expand[1:5,] # inspect first five cases of the combined sequences



 # Example 2: with NA replacement
 data(CouplesCope)
 
 # copy part of the example data
 # excluding code and EDCm for simplification
 na.CouplesCope<-CouplesCope[,2:97] 
 
   
 # fill it with 10% NA's as an example:
 na.CouplesCope[matrix(sample(c(TRUE, rep(FALSE,9)),64*96, TRUE), 64, 96)]<-NA 
 na.CouplesCope[1:5,] # inspect the first 5 cases
 
 # demonstrate na.replace: combine states and fill NA's with zeros!
 my.expand<-StateExpand(na.CouplesCope, 1:48, 49:96, replace.na=0) 
 my.expand[1:5,] # inspect the first 5 cases



## Not run: 
#  # Example 3: Use StateExpand for further analyis 
#  #            or plotting using the Package TraMineR
#               
#  # install.packages("TraMineR") # install "TraMineR" for graphical analysis
#  library(TraMineR) #load TraMineR
# 
#  my.expand<-StateExpand(CouplesCope, 2:49, 50:97) # create combined sequences
# 
#  # create labels for plot
#  couple.labels <-c("no reaction", "stress only", "coping only", "both reactions")  
#  
#  # create a sequence object (the way TraMineR represents sequences)
#  couple.seq <- seqdef(my.expand, labels = couple.labels) 
#  seqdplot(couple.seq)
# 
#  detach(TraMineR) # unloading TraMineR
# ## End(Not run)

Run the code above in your browser using DataLab