Chapter 2.2 Defining sequences
readme.html
and run
2-0_ChapterSetup.R
. This will create
2-0_ChapterSetup.RData
in the sub folder
data/R
. This file contains the data required to produce the
table shown at the bottom of this page.LoadInstallPackages.R
# 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:
partner.month.seq2
which
was created in the same way as partner.month.seq
(see Chapter 2-1 or
2-0_ChapterSetup.R
).seqgranularity
function from the {TraMineRExtras}
package. The resulting
object (already stored in 2-0_ChapterSetup.RData
) was
created with the following code# change granularity --> years instead of months (using modal values)
<- seqgranularity(partner.month.seq,
partner.year.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)
<- print(partner.month.seq[c(4, 8, 16, 21), ], format = "SPS")
col1
# Using recoded monthly data only considering
# spells lasting at least 12 months (column 2)
<- print(partner.month.seq2[c(4, 8, 16, 21), ], format = "SPS")
col2
# Using sequences with yearly granularity (Column 3)
<- print(partner.year.seq[c(4, 8, 16, 21), ], format = "SPS") col3
# 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) |
If you see mistakes or want to suggest changes, please create an issue on the source repository.
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 ...".