Sequence length and granularity

Chapter 2.2 Defining sequences

Click here to get instructions…
# assuming you are working within .Rproj environment
library(here)

# install (if necessary) and load other required packages
source(here("source", "load_libraries.R"))

# load environment generated in "2-0_ChapterSetup.R"
load(here("data", "R", "2-0_ChapterSetup.RData"))


Table 2.2 in Chapter 2.2 compares different approaches towards defining sequence data.

The sequences consist of monthly information on respondents’ partnership status between age 18 to 40 (monthly data). The sequences are stored in the object partner.month.seq and distinguish four states:

State Short Label
Single S
LAT LAT
Cohabiting COH
Married MAR

In addition to using the original data, two alternative approaches of defining the sequences are discussed:

# change granularity --> years instead of months (using modal values)
partner.year.seq <- seqgranularity(partner.month.seq, 
                               tspan=12, method="mostfreq")

Now we can produce Table 2.2 from the book which shows a small selection of four sequences using the three different specifications.

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Table 2.2 - Different alternatives of defining sequences ----
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Using original Sequence data (monthly granularity) (column 1)
col1 <- print(partner.month.seq[c(4, 8, 16, 21), ], format = "SPS")

# Using recoded monthly data only considering
# spells lasting at least 12 months (column 2)
col2 <- print(partner.month.seq2[c(4, 8, 16, 21), ], format = "SPS")

# Using sequences with yearly granularity (Column 3)
col3 <- print(partner.year.seq[c(4, 8, 16, 21), ], format = "SPS")
# Print selection of sequences from differently specified sequence data
tibble(col1, col2, col3) %>%
  kable(col.names = c("Original sequence", 
                      "Strategy 1 – recode", 
                      "Strategy 2 – aggregate")) %>%
  kable_styling(bootstrap_options = 
                  c("striped", "hover", "condensed", "responsive"))
Original sequence Strategy 1 – recode Strategy 2 – aggregate
(S,89)-(LAT,26)-(COH,14)-(LAT,6)-(S,34)-(LAT,4)-(MAR,91) (S,89)-(LAT,26)-(COH,14)-(S,44)-(MAR,91) (S,7)-(LAT,3)-(COH,1)-(S,3)-(MAR,8)
(LAT,13)-(S,6)-(LAT,33)-(S,24)-(LAT,41)-(S,35)-(LAT,10)-(COH,14)-(MAR,88) (LAT,13)-(S,6)-(LAT,33)-(S,24)-(LAT,41)-(S,45)-(COH,14)-(MAR,88) (LAT,1)-(S,1)-(LAT,2)-(S,2)-(LAT,4)-(S,3)-(LAT,1)-(COH,1)-(MAR,7)
(S,56)-(LAT,69)-(COH,47)-(MAR,92) (S,56)-(LAT,69)-(COH,47)-(MAR,92) (S,5)-(LAT,5)-(COH,4)-(MAR,8)
(LAT,4)-(S,134)-(LAT,9)-(COH,3)-(MAR,52)-(LAT,5)-(COH,25)-(MAR,32) (S,150)-(MAR,52)-(S,5)-(COH,25)-(MAR,32) (S,12)-(MAR,5)-(COH,2)-(MAR,3)

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY-NC 4.0. Source code is available at https://github.com/sa-book/sa-book.github.io, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".